Borrar filtros
Borrar filtros

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

1 visualización (últimos 30 días)
Mwafrika
Mwafrika el 20 de Jul. de 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

Respuesta aceptada

Fangjun Jiang
Fangjun Jiang el 20 de Jul. de 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 comentarios
Walter Roberson
Walter Roberson el 20 de Jul. de 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 el 20 de Jul. de 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.

Iniciar sesión para comentar.

Más respuestas (2)

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

Categorías

Más información sobre Workspace Variables and MAT-Files en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by