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

조회 수: 14 (최근 30일)
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
dpb
dpb 2018년 8월 18일
"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.

댓글을 달려면 로그인하십시오.

채택된 답변

Cris LaPierre
Cris LaPierre 2018년 11월 7일
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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 App Building에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by