Unable to plot multiple graphs on same UIAxes (Matlab AppDesigner)

449 views (last 30 days)
Please see my UI attahced. (Matlab App Designer)
I am importing CSV files and plotting each of the three variables(column vectors on Y Axis) against length(X axis). By using checkboxes, I want the user to specify which variables(Y axis) to plot against length(X Axis). Also by importing multiple files, the user should be plot files on same graph. For eg. import 10 files, and plot load vs length in the same graph or UIAxes. However, UIAxes is not responding as expected. It sometimes plots only 4, sometimes 2 and erases the rest of them. In short, it is unable to plot every plot that I want on the same plot.
(You can skip the code and go directly to the Plot section)
Here's my code when pushbutton(Plot) is pressed:
[filename,~] = uigetfile('*.csv;','MultiSelect','on');
s = size(filename);
s = s(1,2);
f = 1;
for f = 1:s
Raw=xlsread(char(filename(f)));
TestLength = app.TestLength.Value;
Points = app.NoofPoints.Value;
%Assigning columns to variables
RawTime = Raw(:,1);
RawExtension = Raw(:,2);
RawLoad = Raw(:,3);
%Calculating Profile
Distance= TestLength/(Points-1);
Length_Points= linspace(0,TestLength,Points);
% Removing slack
RawLoad(RawLoad<10)=0;
%findpeaks(RawLoad,RawTime,'Annotate','extents','WidthReference','halfheight');
[peaks,ind] = findpeaks(RawLoad);
P = size(peaks);
P = P(1);
i=1;
for i=1:P
ext(i)=RawExtension(ind(i),1);
end
%Stiffness
stiffness = peaks./ext';
if app.LoadCheckBox.Value==1
yyaxis (app.UIAxes,'left')
plot(app.UIAxes,Length_Points(1:P),peaks,'-')
ylim(app.UIAxes,[0 600]);
xlim(app.UIAxes,[0 TestLength]);
hold(app.UIAxes);
end
if app.StiffnessCheckBox.Value==1
yyaxis (app.UIAxes,'left')
plot(app.UIAxes,Length_Points(1:P),stiffness,'--')
xlim(app.UIAxes,[0 TestLength]);
hold(app.UIAxes);
end
if app.ExtensionCheckBox.Value==1
yyaxis (app.UIAxes,'right')
plot(app.UIAxes,Length_Points(1:P),ext,':')
ylim(app.UIAxes,[0 10]);
xlim(app.UIAxes,[0 TestLength]);
hold(app.UIAxes);
end
end
  1 Comment
dpb
dpb on 18 Aug 2018
"I don't do GUIs" so not very adept but I note
hold(app.UIAxes);
is scattered around quite a lot, but I never see a
hold(app.UIAxes,'on');
to add plots to a given axes...
hold
by itself simply toggles the state from present state to the other; looks to me like that could possibly be the source of much of the variability of what is/is not "erased".
If you want to add more to a given axes, it must be in the "hold on" state; you need to ensure that you know whether you are adding or creating new without fail every time plot() is called.
It's more efficient to create a full array of X,Y columns and call plot just once for the array than to call it repetitively as well.
No real idea if that's the actual problem or not, just an observation.

Sign in to comment.

Accepted Answer

Cris LaPierre
Cris LaPierre on 7 Nov 2018
In appDesigner, you would use the hold(ax,___) syntax.
For example, in one of my apps, I do the following:
hold(app.UIAxes,'on')
app.Sa_avg = plot(app.UIAxes, app.pO2, SaO2_avg,':k');
app.Sa = plot(app.UIAxes, app.pO2, SaO2);
hold(app.UIAxes,'off')
  4 Comments

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!