Ho to reduce the table to 1dim?

I use the GUIDE option and placed a table.
The table size is 4×6.
I want to have it 1×6 -> I tried to delete the extra rows with no success. It keep on returning them when I press Apply/OK

2 commentaires

Azzi Abdelmalek
Azzi Abdelmalek le 13 Fév 2013
How did you do that?
Nimrodb
Nimrodb le 13 Fév 2013
I added a table with the GUI tool - the default is 4x2
How do i reduce it to 1x2 for ex.?

Réponses (1)

Sean de Wolski
Sean de Wolski le 13 Fév 2013

0 votes

A uitable's size is determined by the size of its 'Data' property. So change that:
h = uitable('Data',rand(4,6));
%%To Reduce it:
set(h,'Data',1:6)

7 commentaires

Nimrodb
Nimrodb le 13 Fév 2013
Modifié(e) : Nimrodb le 13 Fév 2013
thanks.
In what function do I place it? In the table CreateFcn function?
Sean de Wolski
Sean de Wolski le 13 Fév 2013
Whereever you want to reduce the size. Whether it's the createfcn or some callback, it's kind of up to you...
Nimrodb
Nimrodb le 13 Fév 2013
Modifié(e) : Nimrodb le 13 Fév 2013
Found the solution in the following link (basically it's as Sean wrote)
however, I do have an issue now. I wrote in the CreateFcn:
set(hObject, 'Data', cell(1,6));
Before - the table was:
K>> get(hObject, 'Data')
ans =
'' '' '' '' '' ''
'' '' '' '' '' ''
'' '' '' '' '' ''
'' '' '' '' '' ''
And now, it's:
K>> get(hObject, 'Data')
ans =
[] [] [] [] [] []
Do you know why?
OK - this is what's needed:
c = cellfun(@(x) '',cell(1,6),'uniformoutput',false);
set(hObject, 'Data', c);
Thanks to my friend Ohad who helped me...
Not sure why you need the cellfun():
uitable('Data',cell(1,6))
Just calling the below will create an empty cell.
cell(1,6)
Nimrodb
Nimrodb le 20 Fév 2013
Sean - because I wanted to reduce a table - not add cells to it. As you can see from my prev' comment - the cell type when using your format gave me NaN values ([]) and not cell ('') or whatever this format is
So
repmat({''},1,6)
?

Cette question est clôturée.

Question posée :

le 13 Fév 2013

Clôturé :

le 20 Août 2021

Community Treasure Hunt

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

Start Hunting!

Translated by