Trouble with Ylim using addaxis

3 visualizzazioni (ultimi 30 giorni)
Catherine
Catherine il 12 Lug 2013
I can change the Ylim values, but it doesn't change the position of the line on the figure. What am I doing wrong?
Example code:
x = 1:10;
y = x.^2;
figure(1)
plot(x,y)
[hplts,hax2] = addaxis(x,zeros(size(y)),'linewidth',1.5);
% the line is at 0
figure(2)
plot(x,y)
[hplts,hax2] = addaxis(x,zeros(size(y)),'linewidth',1.5);
set(hax2,'Ylim',[0 10]);
% the line is now at 5

Risposte (2)

Catherine
Catherine il 16 Lug 2013
I was able to send this problem to a friend who figured it out. It is a simple fix with one input argument.
x = 1:10;
y = x.^2;
figure(1) % original y limits
plot(x,y)
[hplts,hax2] = addaxis(x,zeros(size(y)),'linewidth',1.5);
figure(2) % changing the y limits to [0 10]
plot(x,y)
[hplts,hax2] = addaxis(x,zeros(size(y)),[0,10],'linewidth',1.5);

Jan
Jan il 12 Lug 2013
Please explain it explicitly, when you use a function, which is not part of Matlab's toolboxes. I guess, that you use FEX: addaxis, but checking this takes some of my time. And downloading this submission to be able to read its instructions is something I do not do to answer a question.
I assume you have to change the limits of the axes the diagram is drawn to:
H = axes('YLim', [0, 10]);
plot(x, y);
[hplts,hax2] = addaxis(x,zeros(size(y)),'linewidth',1.5);
...
  3 Commenti
Jan
Jan il 12 Lug 2013
@Catherine: "does not work" is not explicit enough to understand, if you get an error message or if and how the results differ from your expectations.
All Matlab related questions are welcome in this forum. The less details have to be guessed, the easier and more likely is the creation of a matching answer.
Catherine
Catherine il 16 Lug 2013
It gives the same exact wrong answer as the original problem I posted. I have been using Matlab for the past 17 years and I rarely post questions to the forum because of this kind of attitude. I spent a great deal of time searching the forums for an answer before posting. I posted a clear concise set of lines of code that illustrate the problem I was having. I don't know how much more clear I could be other than adding FEX:addaxis. No one asked you to respond if you didn't have the time to do so.

Accedi per commentare.

Categorie

Scopri di più su MATLAB in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by