MATLAB Answers

Jonathan Wang

How to select/highlight a cell in the uitable automatically? Thank you.

Asked by Jonathan Wang
on 1 May 2011


I am working on part of my project, which the code update the output automatically if user chooses some cell in the uitable:

suppose we have a 2 rows * 1 column in the uitable like the following:



In my projects, A and B correspond to different outputs: they plot different curves in the same axis. What I want to do is that:

1, when user chooses A, we plot the curve A in the axes,

2, when user chooses B, we plot the curve B in the axes,

3, if user chooses both A and B, the code would plot the curve A in the axes, and update the uitable with only A selected, ie, we force to choose one cell at one time.

My question is that: in case 3, when users chooses both A and B, how can I update uitable to make only A chosen/hightlighted? I can re-set the uitable, but I don't know to make A to be chosen automatically after I re-set the uitable.

Thank you.




No products are associated with this question.

2 Answers

Answer by Andrew Newell
on 2 May 2011
 Accepted answer


thank you.

The only thing you can do progamatically is emulate that a cell was selected... it won't highlight the cell, merely activate the cells callback for a specific cell if you want your table's cell selection event handler to do something with that specifically.
It's not pretty but it works...

eventdata = struct('Indices',[row col]); % row/col for cell to activate...

uitableMyTable_CellSelectionCallback(handles.uitableMyTable,eventdata,handles); % where uitableMyTable is your uitable tag

on 7 Mar 2013

it's a pity. Generating a callback cannot affect which cell is highlighted.

Answer by Teja Muppirala
on 2 May 2011

For what you are trying to do, a listbox would be a more natural choice.

Here 'Max = 1' is saying that you can only select one at a time.

uicontrol('style','listbox','String',{'A' 'B'},'Max',1,'units','n','position',[0 0 .1 1],'background','w')


And you CAN select listbox entries programatically.

really thank you Teja. I actually have two uitables, each of which has multiple columns, so I gotta use uitables. I used A and B in my question to make it simple.

Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!