How to set UIAxes min and max lim for plot in app designer ?

37 ビュー (過去 30 日間)
farzad
farzad 2020 年 4 月 11 日
コメント済み: ghaith hamdi 2021 年 11 月 3 日
Hi All
to set a min and max limit for my UIAxes in add designer I use :
ax=app.UIAxes;
ax.YLim([minlim,maxlim])
but I get the error :
Subscript indices must either be real positive integers or logicals.
  7 件のコメント
farzad
farzad 2020 年 4 月 13 日
not at all, I have already written the handle I used in the above comments. nothing about linkaxes. I took the derivative of the Y axis : since it was dispalcement and I wanted to have the velocity
farzad
farzad 2020 年 4 月 13 日
編集済み: farzad 2020 年 4 月 13 日
my bad, I was defining the minumum and max before derivating, but doing the following lines. it gives the minimum of all the present signals in the UIAxes too smaller than the actual minimum. I mean, if I have 3 plots, the minimum of the 3 plots be -3 , with the following I get -40
minlim=0;
maxlim=0;
for i=1:numel(app.UIAxes.Children)
if minlim==0
minlim= min(app.UIAxes.Children(i).YData);
else
if abs(minlim)>abs(min(app.UIAxes.Children(i).YData))
minlim=min(app.UIAxes.Children(i).YData);
end
end
if maxlim==0
maxlim= max(app.UIAxes.Children(i).YData);
else
if abs(maxlim)<abs(max(app.UIAxes.Children(i).YData))
maxlim=max(app.UIAxes.Children(i).YData);
end
end
end
ax=app.UIAxes;
ax.YLim=[minlim,maxlim];

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

採用された回答

Adam Danz
Adam Danz 2020 年 4 月 13 日
編集済み: Adam Danz 2020 年 4 月 13 日
It looks like what you want to do is
axis(app.UIAxes, 'tight')
Your current code does not give you the minimum of all plotted signals. It just gives you the minimum (and maximum) of the last plotted signal listed in app.UIAxes.Children since you're overwriting the minlim and maxlim values upon each iteration of the for-loops.
  8 件のコメント
farzad
farzad 2020 年 4 月 13 日
yes, I repeate it for another line and that gives the second derivative. but anyway, when I removed that first line or copied the values of second row to the first row, this problem vanishes. so I think it's not a problem of derivation
ghaith hamdi
ghaith hamdi 2021 年 11 月 3 日
Thank you so much! this is exactly what I needed!!

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

その他の回答 (1 件)

Tommy
Tommy 2020 年 4 月 11 日
Use
ylim(ax, [minlim,maxlim])
instead.
  3 件のコメント
Tommy
Tommy 2020 年 4 月 12 日
You get an error? Or the limits don't change?
Are you able to post all of your code, or at least enough for us to plot what you are trying to plot?
farzad
farzad 2020 年 4 月 12 日
Well I differentiate the vertical axis. And the axis limits don't change from the original. Sorry that I can't put the whole code but I think I have been descriptive

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

カテゴリ

Help Center および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by