Select lines from table to plot in MATLAB GUI

Hi all!
I am loading several data to plot in a matlab gui (built in GUIDE).
While I am loading the data I have built a table that it is updated with the titles of each spectrum that is loaded.
Is it possible to select multiple rows of the table and update the plot with the selected spectra only???
If yes could anyone provide me with any hint?
Or at least how could I export the INDEX of the selected table rows?
Please find attatched the GUI snapshot for better understanding of my question!
Thank you in advance

 Akzeptierte Antwort

Voss
Voss am 21 Jan. 2022

0 Stimmen

You can create one line for each spectrum (this would probably be in the plot button Callback) and then set the visibility of the lines in the table's CellSelectionCallback function. Something like the code below. You can copy/paste the code and run it on your system to see how it works, and then take the relevant parts and adapt them to your existing code. (I can't really demonstrate the table cell selection callback here, as far as I can tell.)
function main_gui()
handles.figure = figure();
fpos = get(handles.figure,'Position');
N = 7;
handles.table = uitable( ...
'Data',arrayfun(@(x)sprintf('REQ_%02d',x),1:N,'UniformOutput',false).', ...
'CellSelectionCallback',@cb_select, ...
'Units','pixels', ...
'Position',[fpos(3)-160 10 150 fpos(4)-20]);
handles.axes = axes( ...
'Units','pixels', ...
'Position',[10 10 fpos(3)-180 fpos(4)-20]);
colors = get(handles.axes,'ColorOrder');
handles.lines = cellfun(@(x)line( ...
'Parent',handles.axes, ...
'Color',x, ...
'XData',1:10, ...
'YData',10*rand(1,10), ...
'Visible','off'), ...
num2cell(colors(mod(0:N-1,size(colors,1))+1,:),2));
guidata(handles.figure,handles);
end
function cb_select(src,evt)
handles = guidata(src);
idx = evt.Indices(:,1);
set(handles.lines,'Visible','off');
set(handles.lines(idx),'Visible','on');
end

4 Kommentare

abaza
abaza am 21 Jan. 2022
Hi Benjamin! Thanks for the reply!
My data are 2 matrices. Ymatrix (7 x 1000) and Xmatrix (7 x 1000).
Plot the data by pressing the plot button : plot(X',Y')
Then I want to select lets say 3 first spectra tiles from the table and plot their correpsonding spectra:
like:
plot(X(1:3,:),Y(1,3,:)).
I see your solution, it works but I would prefer finding a way to export the IDX of the selected spectra from the table, since I want to do more stuff on them afterwards...
Is it possible to get the IDX of the selected spectra?
function cb_select(src,evt)
handles = guidata(src);
idx = evt.Indices(:,1); % <- here are the indexes of the selected rows
set(handles.lines,'Visible','off');
set(handles.lines(idx),'Visible','on');
end
If you want to store those indexes, you can do so in the handles structure:
function cb_select(src,evt)
handles = guidata(src);
idx = evt.Indices(:,1); % <- here are the indexes of the selected rows
set(handles.lines,'Visible','off');
set(handles.lines(idx),'Visible','on');
% store the indexes and save the handles structure:
handles.selected_idx = idx;
guidata(handles.figure,handles);
end
abaza
abaza am 21 Jan. 2022
Thank you so much!
Voss
Voss am 21 Jan. 2022
You're welcome!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Creating, Deleting, and Querying Graphics Objects finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 21 Jan. 2022

Kommentiert:

am 21 Jan. 2022

Community Treasure Hunt

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

Start Hunting!

Translated by