Error when two uitables with CellSelectionCallback interact
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
The code in the end demonstrates a behavior that seems weird to me, or I might miss something.
There are 2 uitables. Each has CellSelectCallback. Table1 has some cells filled with something (e.g. some categories describing a building).
When you click a category(cell), callback of table1 sends elements of a selected category to table2. You click different categories in table1, and you get their elements in table2. Very simple :)
When you click a cell in table2, callback of table2 displays this cell. Very simple :)
Now the problem.
1) I have a cell in table2 selected
2) Then I make new selection in table1
3) That causes execution of callback of table1, where there is set command which updates table2.
4) But …. for some reason this set command (inside callback1) causes execution of callback2 …. with undefined eventdata.Indices (I put breakpoints in each function to make it clear)
5) Of course, Matlab throw an error: Attempted to access eventdata.Indices(1,:); index out of bounds because size(eventdata.Indices)=[0,2].
6) I modified my code to get rid of this error.
if ~isempty(eventdata.Indices)
iSelect = eventdata.Indices(1,:);
else
iSelect = 1;
end
My questions: Is there an explanation of such behavior of set command? Is there a more intelligent way to deal with such problem?
Thank you. Pavel
function TablesTest( )
data1 = {'Envelope';'HVAC';'Utility'};
data2 = {{'wall','roof','window'};{'furnace','vent'};{'electricity','gas'}};
hF = figure;
ht1 = uitable(hF,'units','normalized','pos',[0.02 0.5 0.95 0.45],'Data',data1,...
'CellSelectionCallback',@showDetails);
ht2 = uitable(hF,'units','normalized','pos',[0.02 0.02 0.95 0.45],'Data',data2{1},...
'CellSelectionCallback',@displaySmth);
function showDetails(ht, eventdata)
iSelect = eventdata.Indices(:,1);
set(ht2,'Data',data2{iSelect})
end
function displaySmth(ht, eventdata)
iSelect = eventdata.Indices(1,:);
Names = get(ht,'Data');
selNames = Names{iSelect};
display(['Selected Names: ',selNames])
end
end
0 Kommentare
Antworten (0)
Siehe auch
Kategorien
Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!