Add a display name to each plot. then turn on the legends at the end
ax = axes;
hold(ax,'on');
for i = 1:10
plot(ax,1:10,1:10,'DisplayName',['line' num2str(i)])
end
legend(ax);
Please note that your variables names and plots will not persist after the function finish executing.
If you want to store this then please add property to your app, then you can store the values in this property.
Also the way this code is written, it does not allow multi select on the file list. if you want to do that you may have to edit this code.
function FilesListBoxValueChanged(app, event)
switch app.HoldPlotsCheckBox.Value
case 0
cla(app.UIAxes)
filename = app.FilesListBox.Value;
data = xlsread(filename);
plot(app.UIAxes, data(:,1), data(:,2),'DisplayName',filename);
case 1
hold(app.UIAxes,'on');
filename = app.FilesListBox.Value;
data = xlsread(filename);
pl=plot(app.UIAxes, data(:,1), data(:,2),'DisplayName',filename);
legend(app.UIAxes);
hold(app.UIAxes,'off');
end
end
Best Answer