0

I have created a uitable consists of, say, four columns.

colu={{'Sweet' 'Beautiful' 'Caring'},'numeric', 'numeric','numeric'}
dat={1 2 3 []; 4 5 6 []; 7 8 9 []};
A=uitable('outerposition',[0 0 1 1],'ColumnFormat',colu,'Data',dat);

What I wanted to do now is that when the code is run, and I choose 'Sweet' in the pop-up in the first cell, the cell (1,4) displays dat(1,1), or when I choose 'Beautiful' in the second cell in the first column, the cell (2,4) displays dat(2,1). Unlike in a popupmenu outside a uitable, I am not able to use get(popup,"value').

How could I possibly do what I wanted to? Thanks in advance!

Robert Seifert
  • 25,078
  • 11
  • 68
  • 113
  • [in my question here you can find some ready code](http://stackoverflow.com/questions/19406767/is-it-possible-to-prevent-an-uitable-popup-menu-from-popping-up-or-how-to-get) - I also could guess that you get similar problems. – Robert Seifert Nov 20 '13 at 09:09

1 Answers1

1

You'll have to use the CellEditCallback property, which is a global callback that gets triggered when any cell is edited. There are no callbacks you can set on individual cells.

A pseudo-code template that should get you started:

function cellEditCallback(hTable, editEvent)
    % get changed index
    changedIndex = editEvent.Indices;
    if changedIndex is a popup-cell:
        % check new value
        newValue = editEvent.NewData;
        % set data in appropriate cell to corresponding value
        ...

As an aside, the columnFormat in the example does not match the data. It specifies column 1 as a popup-column, while according to your data, it should be column 4. I also had to change [] to '' to make the popup work and set('ColumnEditable', logical([0,0,0,1])).

See e.g.

http://www.mathworks.de/products/matlab/examples.html?file=/products/demos/shipping/matlab/uitabledemo.html

for a more comprehensive example uitable application.

sebastian
  • 9,526
  • 26
  • 54
  • "There are no callbacks you can set on individual cells." -disagree, using the indices you get with the callback and a little switch/case algorithm and you get exactly that. – Robert Seifert Nov 20 '13 at 09:12
  • Sure you can do that, it's what my pseudo-code example does - if you'd extend the `if changedIndex is a ...` part. I was referring to the OP's attempt/example of `get(popup, 'value')`. I wasn't claiming that reacting on a edit-action on a per-cell basis is impossible, just that there are no ready-made callbacks to do that. – sebastian Nov 20 '13 at 09:19
  • you're right, I was a little confused of your formulation. Nevermind ;) – Robert Seifert Nov 20 '13 at 09:23