Adding a second scaled y-axis to a plot

조회 수: 4 (최근 30일)
Christian Nørgaard
Christian Nørgaard 2018년 5월 25일
댓글: Ameer Hamza 2018년 5월 25일
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
Christian Nørgaard 2018년 5월 25일
IT WORKED!!! THANKS !!!! 6 hrs of lovely troubleshooting is finally done!!!!!!!! Thanks a lot!
Ameer Hamza
Ameer Hamza 2018년 5월 25일
You are welcome.

댓글을 달려면 로그인하십시오.

추가 답변 (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