Azzera filtri
Azzera filtri

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

1 visualizzazione (ultimi 30 giorni)
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

Risposta accettata

Fangjun Jiang
Fangjun Jiang il 20 Lug 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 Commenti
Walter Roberson
Walter Roberson il 20 Lug 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 il 20 Lug 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.

Accedi per commentare.

Più risposte (2)

Mwafrika
Mwafrika il 26 Lug 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 il 2 Ott 2011
It was very helpful, thanks!

Categorie

Scopri di più su Workspace Variables and MAT-Files in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by