How do I offset a plot curve only in the y axis?

I have a problem to offset the curve in the y axis so it starts at y = 2.5 instead of 0. My problem is that the equation does not have a y function, will it be possible to offset it anyways?
syms x
ezplot(-0.5*x.^(1.85)) / (2*5^(0.85));

 Accepted Answer

Try this:
figure
ezplot(@(x) (-0.5*x.^(1.85)) / (2*5^(0.85)));
L1 = findobj(gca, 'Type','Line');
L1.YData = L1.YData + 2.5;
set(gca, 'YLim',[min(ylim) max(ylim)+2.5])
I needed to make a few changes so it would run without errors (2020a).

8 Comments

It works if it acts alone but if i want to add additional plot functions it will go back to the origin start point
I do not understand.
Please provide an example, and a description of what you want the result to be. (You can use the hold function to plot additional functions on the same axes.)
.
Ok so for example I have a line from the origin up to 2.5 from that point [0 2.5] I want the equation to start the ezplot curve but for some reason it starts at the origin every time. Im new to all of this so I dont know alot at the moment.
plot(x,y)
hold on;
plot([0 0], [0 2.5])
ezplot(@(x) (-0.5*x.^(1.85)) / (2*5^(0.85)));
The curve starts at the origin (0,0) and goes to (6.283,-1.907) because that is the way the code is written. To get a different result, use a different function.
The additional code I provided will have it start at (0,2.5) and go to (6.283,0.5926).
It´s more clear now, thank you. Could you please explain what these three lines of code you provided actually do?
L1 = findobj(gca, 'Type','Line');
L1.YData = L1.YData + 2.5;
set(gca, 'YLim',[min(ylim) max(ylim)+2.5])
You are using the ezplot funciton, so I need to get the data it used to calculate the line that it drew. Those lines find the handle to the line object, and then get the ‘x’ and ‘y’ values from it. See the documentation section on Find Objects for details.
The whole concept of Graphics Objects and such in MATLAB handle graphics is much more than I want to describe here. I refer you to the documentation for a complete explanation.
I will read them, thank you for bearing with me.
As always, my pleasure!

Sign in to comment.

More Answers (0)

Products

Release

R2019a

Community Treasure Hunt

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

Start Hunting!