write data to uitable

the question is : in pushbutton callback i read this code:
C=[h1 h2 h3 h4 h5 h6];
set(handles.uitable1,'DATA',C);
the uitable1 display the result in the first row,
while i will change the value of C, when i push the pushbutton again, how to write C to sceond row?

 Accepted Answer

current_data = get(handles.uitable1, 'data');
newdata = [current_data; C];
set(handles.uitable1, 'data', newdata);

12 Comments

ww ww
ww ww on 11 Dec 2017
thank you ,I read this code ,but when i push the pusbutton ,the uitable show two row .
ww ww
ww ww on 11 Dec 2017
i want when i fist push the button ,the uitable show the first row,when i second push,the uitable show the data in second row ,and so on ,the first row save the date which not changed.
Jan
Jan on 11 Dec 2017
@ww ww: I do not really understand, what you are asking for. What should appear in the first and second row at the third click?
ww ww
ww ww on 11 Dec 2017
such as,I have an edit1 ,an uitable1 and a pushbutton1,I write data to edit1,after some caculations,I get the data C and show in frist row of uitable, now,I will write different data to edit1,then I get the different data C,so,I want to show the different data C in sceond row of uitable1,if I change data C again,it will be show in third row.
ww ww
ww ww on 11 Dec 2017
@Jan Simon: thank you very much,how can i do this?
Jan
Jan on 11 Dec 2017
@ww ww: But this is exactly what Walter's suggestion does.
By the way, I asked: "What should appear in the first and second row at the third click?" As far as I understand, the answer is: "The values create by the first and second click".
ww ww
ww ww on 11 Dec 2017
Edited: ww ww on 11 Dec 2017
@Jan Simon but,it can not work,i took Walter Roberson advice,i mean,when i frist click,uitable show like this
this is my code
C=[h12 q3 pwf2 cy2 glr2 qd]; %one row
set(handles.uitable3,'DATA',C);
current_data = get(handles.uitable3, 'data');
newdata = [current_data; C];
set(handles.uitable3, 'data', newdata);
i mean,i have only one pushbutton,when i frist click,uitable show the first row,when i second click ,the data show in second row ,but,now when i second click, the data covered the first row.
Remove the
set(handles.uitable3,'DATA',C);
ww ww
ww ww on 11 Dec 2017
@Walher Roberson think you very much ,that is ok!
@Walter Roberson: sorry,I try agian this code ,it is can not work again,if i remove:
set(handles.uitable3,'DATA',C); % code
how can i get data from uitable? this is error
ww ww
ww ww on 12 Dec 2017
add an pushbutton~that is ok
For this to work the first time, the data property has to have been left initialized to its default [] .
For it to continue to work, the number of columns in C needs to be the same as the number of columns in the existing table.
I suspect some of your calculated h values might be empty, giving you a C shorter than previous rows. Use the debugger to find out.

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!