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

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 commentaires

Adam Danz
Adam Danz le 11 Avr 2020
Modifié(e) : Adam Danz le 11 Avr 2020
1) Why make a copy of the app.UIAxes handle instead of setting the ylim directly from
app.UIAxes.YLim = [minlim,maxlim];
2) You forgot the equal sign (but use the syntax above rather than making a copy of the handle).
ax.YLim = [minlim,maxlim];
Exactly ! the problem was the syntaxing, the equal was missing and no paranthesis was needed.thank you
Upon first glance, I missed the missing equal sign, too ;)
Adam, I tried this, but it seems that the UIAxes limits remain those of first plot ( since I plot a signal. then differentiate the Y axis.) this causes the axes limit do not change with this command
You might be using the wrong axes handle. Did you happen to use linkaxes command? What do you mean "differentiate the y axis"?
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 le 13 Avr 2020
Modifié(e) : farzad le 13 Avr 2020
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];

Connectez-vous pour commenter.

 Réponse acceptée

Adam Danz
Adam Danz le 13 Avr 2020
Modifié(e) : Adam Danz le 13 Avr 2020
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 commentaires

farzad
farzad le 13 Avr 2020
Modifié(e) : farzad le 13 Avr 2020
Thank you Adams, I tried this, all of these methods give me this, even with your suggestion : Actually , in the second derivative, the plot goes to the top most of the plot zone, and in first derivative, it goes to the bottom of the plotted zone, and the white empty zone remians above.
Adam Danz
Adam Danz le 13 Avr 2020
Modifié(e) : Adam Danz le 13 Avr 2020
I instantly see why. Look at the green spike at x~~0. You have to remove that spike.
farzad
farzad le 13 Avr 2020
Modifié(e) : farzad le 13 Avr 2020
I use the following to derivate each time, why should I have such a spike ?
app.UIAxes.Children(i).YData= gradient(app.UIAxes.Children(i).YData)./gradient(app.UIAxes.Children(i).XData);
I checked my data, the first two rows of that signal that causes that big negative acceleration: between the time 0 to 0.001953. It goes from 0 to 2.88 and then with the same time increment to 2.91 , so the second derivative sounds too hugely negative not ?
Have you looked at the values for that line around x=0?
Plot that line only and zoom into around x=0.
I checked my data, the first two rows of that signal that causes that big negative acceleration: between the time 0 to 0.001953. It goes from 0 to 2.88 and then with the same time increment to 2.91 , so the second derivative sounds too hugely negative not ?
so the second derivative sounds too hugely negative not ?
I can't estimate it without seeing the data (note, I'm not asking for the data).
The line of code you shared above is computing the 1st derivative, isn't it?
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
Thank you so much! this is exactly what I needed!!

Connectez-vous pour commenter.

Plus de réponses (1)

Use
ylim(ax, [minlim,maxlim])
instead.

3 commentaires

this does not work for appdesigner
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?
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

Connectez-vous pour commenter.

Catégories

En savoir plus sur Develop Apps Using App Designer dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by