Hi,
I've created a GUI in Matlab with 4 pushbuttons and a table. I want to set initial values in the table when the GUI opens, and then change the values in the table when one of the buttons is pressed.
I'm new to this, what do I need to do to set the data in my uiTable1? I feel like this should be easier then I'm making it. I don't want the user to be able to change the cells of the table, I just want to change the cells of the results from a code that I will run as a display.
Thanks,

댓글 수: 5

Patrick
Patrick 2015년 3월 5일
I got the set command to work. Now I'm having trouble figuring out how to change the data in the table only 2 cells at a time. For example the table is 2x10. When the user clicks a button, I only want data in cells (1,1) and (2,1). Then when they push the button a second time, I want to read the table values that are already there but then add in cells (2,1) and (2,2). Do you have any suggestions for this? I'm having trouble figuring out which cells already have data using the getappdata command.
Get the old values using the get command, concatenate them together and then set them again:
newVals = randn(1,2);
oldVals = get(t,'Data');
newVals = [oldVals ; newVals];
set(t,'Data',newVals);
Patrick
Patrick 2015년 3월 5일
편집: Patrick 2015년 3월 5일
This works, great, however I want the first column to be replaced, but then every column after that to concatenate. How can I do this?
Is there a way to set a limit on the concatentation? For example once there are 10 columns I want the function to not allow any more concatenations?
And once the table is full, is there a way to sum all of the values in each column and return a result in a popup window?
Patrick
Patrick 2015년 3월 5일
I figured out my first problem with how to replace the first value. Now I need to figure out how to limit the number of concatentations and then return a popup window at the end
Brendan Hamm
Brendan Hamm 2015년 3월 5일
Sure just place this in an if statement (checking the size of the 'Data'), make a new figure, and add a uitable or annotation('textbox',...) with the data.

댓글을 달려면 로그인하십시오.

 채택된 답변

Brendan Hamm
Brendan Hamm 2015년 3월 5일

8 개 추천

Use the set command:
f = figure;
d = randn(10,3); % Make some random data to add
t = uitable(f);
set(t,'Data',d); % Use the set command to change the uitable properties.
set(t,'ColumnName',{'a';'b';'c'})

댓글 수: 3

Saeid
Saeid 2016년 12월 11일
Hi Brendan, I was just looking for this answer and your suggestion helped me a lot, thanks!
Brendan Hamm
Brendan Hamm 2016년 12월 11일
Glad to hear this helped out. I'm a bit surprised to see how many views this one answer has ... must be a popular topic.
abdulghani aldhaibani
abdulghani aldhaibani 2018년 4월 26일
thank you ... Brendan Hamm

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Yingcai
Yingcai 2016년 12월 1일
편집: Yingcai 2016년 12월 1일

1 개 추천

t = handles.uitable1;
d = randn(10,3); % Make some random data to add
set(t,'Data',d); % Use the set command to change the uitable properties.
set(t,'ColumnName',{'a';'b';'c'})
%yingcai1012@hotmail.com

카테고리

도움말 센터File Exchange에서 Programming Utilities에 대해 자세히 알아보기

태그

질문:

2015년 3월 5일

댓글:

2018년 4월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by