Hi all
I am aware that MATLAB lacks the option of adding multiple legends
strangely there are some solutions ,and this , that might be feasible in matlab base. but I need to do that in app designer, while I have a list box that reads the files names from a folder and when I hover over each one of them and click on them, it will plot it and based on the hold condition I activate, it plots the next chosen file over the previous.
I went as far as the code you see bellow but it still keeps one single legend name. Is there any hope to resolve this ?
% Value changed function: HoldPlotsCheckBox
function HoldPlotsCheckBoxValueChanged(app, event) value = app.HoldPlotsCheckBox.Value; end % Value changed function: FilesListBox
function FilesListBoxValueChanged(app, event) names = {};plots=[]; switch app.HoldPlotsCheckBox.Value case 0 cla(app.UIAxes) drawnow; % FocusUIFigure(app.UIFigure)
% app.UIFigure.Visible = 'off';
% app.UIFigure.Visible = 'on';
filename = app.FilesListBox.Value; data = xlsread(filename); plot(app.UIAxes, data(:,1), data(:,2)); case 1 hold(app.UIAxes); drawnow;% FocusUIFigure(app.UIFigure)
% app.UIFigure.Visible = 'off';
% app.UIFigure.Visible = 'on';
filename = app.FilesListBox.Value; names{end+1} = filename; data = xlsread(filename); pl=plot(app.UIAxes, data(:,1), data(:,2)); plots(end+1)=pl; legend(app.UIAxes,plots,names); hold(app.UIAxes); end end % Button pushed function: UpdatefilesButton
function UpdatefilesButtonPushed(app, event) files = dir('*.xlsx'); app.FilesListBox.Items = {files.name}; end
Best Answer