Add a new row in an uitable dynamically using a pushbutton
24 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (2 件)
Joseph Cheng
2014 年 8 月 13 日
編集済み: Joseph Cheng
2014 年 8 月 13 日
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 件のコメント
Joseph Cheng
2014 年 8 月 19 日
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
2014 年 8 月 13 日
編集済み: Julian
2014 年 8 月 13 日
2 件のコメント
imene. B
2016 年 7 月 11 日
編集済み: imene. B
2016 年 7 月 11 日
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);
参考
カテゴリ
Help Center および File Exchange で Argument Definitions についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!