Filter löschen
Filter löschen

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

1 Ansicht (letzte 30 Tage)
Mwafrika
Mwafrika am 20 Jul. 2011
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

Akzeptierte Antwort

Fangjun Jiang
Fangjun Jiang am 20 Jul. 2011
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 Kommentare
Walter Roberson
Walter Roberson am 20 Jul. 2011
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 am 20 Jul. 2011
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

Mwafrika
Mwafrika am 26 Jul. 2011
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 am 2 Okt. 2011
It was very helpful, thanks!

Kategorien

Mehr zu Workspace Variables and MAT-Files finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by