I'm trying to plot a curve using pchip but it is filling data points in the wrong direction.
x = Tempdif;
y = Pres;
xq = linspace(-1.5, 2, 200);
pp = pchip(x, y);
yq = ppval(p, xq);
figure(1)
plot(xq, yq, '-r',x, y, 'ob' )
This is what I want it to look like but smooth
This is what I'm getting
How can I get the red line to be processed horizontally instead of vertically?
UPDATE: Trying the answer by John D'Errico the values on the axes have been flipped

답변 (1개)

John D'Errico
John D'Errico 2018년 4월 30일
편집: John D'Errico 2018년 4월 30일

0 개 추천

You are fitting the function in the WRONG direction. This NOT a problem of fitting pressure as a function of temp difference. There is no functional relationship there.
The relationship that you have seems to be of the form tempdif(pressure). Thus as pressure changes, the temperature difference changes dependently.
But fine, you can still plot it with the variables on the axes you have chosen.
y = Tempdif;
x = Pres;
xq = linspace(min(x), max(x), 200);
pp = pchip(x, y);
yq = ppval(pp, xq);
figure(1)
plot(yq, xq, '-r',y, x, 'ob' )
xlabel 'Temperature difference (C)'
ylabel 'Pressure (nPa)'
You did make a good choice to use pchip instead of spline.

댓글 수: 1

Electric Sheep
Electric Sheep 2018년 5월 3일
Thanks that's got the red line going in the right direction but somehow is flipping the axes for the data points. It's a plot of atmospheric temperature bias so I'm using the pressure as a representation of height.

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

카테고리

도움말 센터 및 File Exchange에서 Interpolation에 대해 자세히 알아보기

태그

질문:

2018년 4월 30일

편집:

2018년 5월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by