Adding a second scaled y-axis to a plot

4 次查看(过去 30 天)
Hello,
I have been trying to figure out how to add a second scaled y-axis ( or even just a second y-axis) and even after reading through several Matlab forum posts it still does not work. I was wondering if anyone out there, would help me figure out what I am doing wrong.
My personal thoughts on what is wrong is something to do with the fact that I am trying to plot a curve fit on a set of data and when I tell Matlab to plot according to some x-axis is can not compute my request.
My matlab code so far:
x=[
0
3
6
9
11.5
13.952
];
y=[
0.905
0.900
0.850
0.800
0.788
0
];
v=[
0
3
6
9
11.5
13.952
];
p=[
0
2.5
5.1
8.9
11.493
0
];
f=fit(v,p,'poly5')
c=fit(x,y,'exp2')
figure(1)
plot(f)
figure(2)
x= 0: 1.0 : 15;
plot(f);
hold on;
plot(c)
Where x,y are plots for one curve and v,p (x and y coordinates respectivly) for the other curve
I have tried,
x= 0: 1.0 : 15;
plot(x,f);
hold on;
plot(x,c)
and I tried to follow the example given in https://se.mathworks.com/matlabcentral/answers/23591-examples-of-multiple-plots-on-one-graph ( more specifically the accepted answer given by Chandra Kurniawan) , where a problem similar to what I am facing now was asked and answered.
Any help/thoughts/advice is extremely welcome! Thank you in advance

采纳的回答

Ameer Hamza
Ameer Hamza 2018-5-25
You can use yyaxis to plot 2 axis
x = 0:0.1:10;
yyaxis left
plot(x, x);
yyaxis right
plot(x, sin(x))
  6 个评论
Christian Nørgaard
IT WORKED!!! THANKS !!!! 6 hrs of lovely troubleshooting is finally done!!!!!!!! Thanks a lot!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with Curve Fitting Toolbox 的更多信息

产品


版本

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by