How to place the x axis pointing downward and the y axis horizontally?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I have one project in which one of the questions asks to interpolate the temperature of a lake as a function of its depth. The tricky part is, the teacher wants the x axis pointing downwards ( which means the depth is increasing as we go down) and the y axis horizontally. So far I have researched about this and found no anwers. Does anyone know how to?
x= [0 2.3 4.9 9.1 13.7 18.3 22.9 27.2]; %z data
y=[22.8 22.8 22.8 20.6 13.9 11.7 11.1 11.1];%temperature data
coefs=polyfit(x,y,7); %interpolating polynomial coefficients
pint=polyval(coefs,x); %interpolating polynomial
plot(x, y, 'o', x, pint, '-');
xlabel('z');
ylabel('T');
legend('polynomial interpolation')
0 Kommentare
Antworten (1)
the cyclist
am 26 Mär. 2024
I'm not 100% certain I understand, but here are steps toward what I think you want. Use some or all of them.
First version, I am only renaming your variables to what the actually represent, for my own sanity.
z= [0 2.3 4.9 9.1 13.7 18.3 22.9 27.2]; %z data
T=[22.8 22.8 22.8 20.6 13.9 11.7 11.1 11.1];%temperature data
coefs=polyfit(z,T,7); %interpolating polynomial coefficients
pint=polyval(coefs,z); %interpolating polynomial
plot(z, T, 'o', z, pint, '-');
xlabel('z');
ylabel('T');
legend('polynomial interpolation')
Next, I am swapping the axes for plotting, because it seems like maybe that is what you want?
z= [0 2.3 4.9 9.1 13.7 18.3 22.9 27.2]; %z data
T=[22.8 22.8 22.8 20.6 13.9 11.7 11.1 11.1];%temperature data
coefs=polyfit(z,T,7); %interpolating polynomial coefficients
pint=polyval(coefs,z); %interpolating polynomial
plot(T,z, 'o', pint,z, '-');
xlabel('T');
ylabel('z');
legend('polynomial interpolation')
Finally, I am changing the direction of the "Y" axis (which is plotting the variable z):
z= [0 2.3 4.9 9.1 13.7 18.3 22.9 27.2]; %z data
T=[22.8 22.8 22.8 20.6 13.9 11.7 11.1 11.1];%temperature data
coefs=polyfit(z,T,7); %interpolating polynomial coefficients
pint=polyval(coefs,z); %interpolating polynomial
plot(T,z, 'o', pint,z, '-');
set(gca,"YDir","reverse") % <--------- Here is where I reverse the direction of the axis
xlabel('T');
ylabel('z');
legend('polynomial interpolation')
I'm honestly not sure which of these things you really need, but maybe you can figure it out from these ideas.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Polynomials finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


