필터 지우기
필터 지우기

table in GUI --> data to matrix, expandable array

조회 수: 1 (최근 30일)
Mwafrika
Mwafrika 2011년 7월 20일
Hey Guys,
i'm just working on a GUI and until now i just an extra dat-file for the input of my values.. but now i would like to use the table in the GUI!
So my questions are:
How do get the data input from the editable table in the GUI into a matrix i can use in my m-file?
and how can i add more rows to the table (from the UI) and remove unused ones? (would be even better if this could happen automatically..)
Hope you can give me a hand i just can not find a way,...
Thx
Mwafrika

채택된 답변

Fangjun Jiang
Fangjun Jiang 2011년 7월 20일
First, create an example table.
h=uitable('data',magic(5),'columneditable',true,'RearrangeableColumns','on');
Then, make any arbitrary changes on the data. If you want to get the new data in your .m file, make sure you have access to the handle h.
data=get(h,'data');
If you want to add or remove rows, you can add a button say "add row" and then in the callback function, do something like this.
data=get(h,'data');
data(end+1,:)=0;
set(h,'data',data');
To remove a row, if you could have a way to specify the row number r, for example r=2, you can do.
data=get(h,'data');
data(2,:)=[];
set(h,'data',data);
  댓글 수: 2
Walter Roberson
Walter Roberson 2011년 7월 20일
Small change: "data" will be a cell array, so you cannot set dat(end+1,:) to the numeric value 0. You can set it to {0} or {} or as appropriate.
Fangjun Jiang
Fangjun Jiang 2011년 7월 20일
I am not sure. When I use h=uitable('data',magic(5)), class(get(h,'data')) is double. So it is the other way around. But, in general, yes, should look at the data class to do things differently.

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

추가 답변 (2개)

Mwafrika
Mwafrika 2011년 7월 26일
Thx Fangjun Jiang,
i did it now in a little different way...
i linked my dat file to the table in the GUI using get and csvwrite.. the adding and removing of rows with your code worked fine in combination with this way!
THX again
Mwafrika

Guilherne
Guilherne 2011년 10월 2일
It was very helpful, thanks!

카테고리

Help CenterFile Exchange에서 Workspace Variables and MAT-Files에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by