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

20 ビュー (過去 30 日間)
Neeraj Manthalkar
Neeraj Manthalkar 2018 年 8 月 18 日
コメント済み: Sarvesh Shevade 2021 年 6 月 28 日
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 件のコメント
Kadir AK
Kadir AK 2020 年 12 月 27 日
thank my friend
Sarvesh Shevade
Sarvesh Shevade 2021 年 6 月 28 日
Thank you cris

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeApp Building についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by