Add a new row in an uitable dynamically using a pushbutton
26 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hello everybody
I'm creating an app for making electrical calculations but I have to add rows constantly for entrying new data to be evaluated. I'm using a code i saw on a MatLAB tutorial on Youtube but it doesn't run as I was expected. I would like some help to improve this code and make it works properly.
The code I'm using is:
% --- Executes on button press in pushbutton1.
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)
data=get(handles.uitable1, 'data');
data=str2double(data);
data(end+1,:)=0;
set(handles.uitable1, 'data', data);
I appreciate for your help.
0 Commenti
Risposte (2)
Joseph Cheng
il 13 Ago 2014
Modificato: Joseph Cheng
il 13 Ago 2014
what type of stuff are you sticking in this table? What are you expecting? if the data variable (place a breakpoint at data and see) is a string of numbers? letters?
is data at the get(handles.uitable1,'data') a cell array? if so i wouldn't convert data from a str2double as it could mess up your data depending on whats there. i would just go
data=get(handles.uitable1, 'data');
data(end+1,:)={0}; %if data is a cell or
data(end+1,:)=0; %if data is an array.
set(handles.uitable1, 'data', data);
4 Commenti
Joseph Cheng
il 19 Ago 2014
Has by answers resolved your initial question? if so can you mark it as answered?
To answer your question below i would just convert the cell type into a mat then do the str to number conversion or vice versa. I don't have a sample of your cases so you'll have to check out the different functions and how to perform the conversion.
Julian
il 13 Ago 2014
Modificato: Julian
il 13 Ago 2014
2 Commenti
imene. B
il 11 Lug 2016
Modificato: imene. B
il 11 Lug 2016
thank you very much julian :D
here's my code, it works perfectly
Add a row
% --- Executes on button press in pushbutton1.
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)
data=get(handles.uitable1, 'data');
data(end+1,:)={0};
set(handles.uitable1, 'data', data);
Vedere anche
Categorie
Scopri di più su Argument Definitions in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!