Inserting rows into uitable??
Show older comments
I have a simple gui containing two edit boxes and a push button.On pressing the push button the values of the edit boxes are inserted into a uitable.The code for pushback button callback is:
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
name=get(handles.edit1,'String');%the value of the first edit box
Idno=get(handles.edit2,'String');%the value of the second edit box
g=exist('C:\Users\Animesh\Documents\MATLAB\dbt3.mat')%ckecks for the existence of table
if g==0
comp=[];
dbt3 = uitable('Data',comp,'Position', [25 25 700 200]);
Exist=get(dbt3, 'Data');
New={name,Idno};
comp=[Exist;New]
set(dbt3, 'Data',comp);
save('dbt3')
else
load('C:\Users\Animesh\Documents\MATLAB\dbt3.mat')
dbt3 = uitable('Data',comp,'Position', [25 25 700 200]);
Exist=get(dbt3, 'Data');
New={name,Idno};
comp=[Exist;New]
set(dbt3, 'Data',comp);
save('dbt3')
end
The problem is that when I run it for the first time the control is in the if block and the first row is added into the uitable.But when i run the 2nd time the control goes to the else block but the next row added is the same as the previous row.. Can anyone help?? Thanks a lot in advance..
Accepted Answer
More Answers (0)
Categories
Find more on App Building in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!