I am making a Skew T Chart in matlab and for some reason my isotherms(the diagonal lines on the plot) aren't aligned with the temperature on the x-axis. Is there a way to fix?

6 visualizaciones (últimos 30 días)
clear all;
close all;
[P,H,T,Td,w]=textread('OAX_sounding_corrected.dat', '%f %f %f %f %f');
fileID = fopen('OAX_sounding_corrected.dat','w');
formatSpec = '%f %f %f %f %f\n';
temp1 = -40:.1:50;
press1 = 1050:-50:100;
numtemp1 = numel(temp1);
numpress1 = numel(press1);
for i = 1:numtemp1
for j = 1:numpress1
a(i,j) = temp1(i)+40.*log(.001.*press1(j));
end
end
press1 = transpose(press1);
temp1 = transpose(temp1);
a = transpose(a);
figure
b = contour(temp1,press1,a,16,'k');
hold on
set(gca,'yscale','log','ydir','reverse')
set(gca,'ytick',[100:50:1050])
set(gca,'ygrid','on')
c = T-40.*log(.001.*P);
d = Td-40.*log(.001.*P);
plot(d,P,'g')
plot(c,P,'r')
xlabel("Temperature (°C)")
ylabel("Pressure (hPa)")
title("Temperature vs. Pressure")

Respuestas (2)

Vishwa
Vishwa el 27 de Feb. de 2023
Editada: Vishwa el 27 de Feb. de 2023
To my understanding, there is no error in the output of this MATLAB code. Contours are plotted at right locations, as visible in this figure.
To fix this, you may try the following:
  1. Either modify your expression for a so that contours are generated with matching values of x-ticks, or
  2. You can change the x-ticks to match the contour data points.
Here is the modified code
temp1 = -40:10:50;
press1 = 1050:-50:100;
numtemp1 = numel(temp1);
numpress1 = numel(press1);
for i = 1:numtemp1
for j = 1:numpress1
a(i,j) = temp1(i)+40.*log((1/1050).*press1(j));
end
end
press1 = transpose(press1);
temp1 = transpose(temp1);
temp2 = [-130 -120 -110 -100 -90 -80 -70 -60 -50 temp1'];
a = transpose(a);
figure
b = contour(temp1,press1,a,temp2,'k','ShowText','on');
hold on
set(gca,'yscale','log','ydir','reverse')
set(gca,'ytick',100:50:1050)
set(gca,'ygrid','on')
Refer MATLAB Documentation on contour function which provides instructions to control number of contour lines displayed and there values.
https://www.mathworks.com/help/matlab/ref/contour.html#d124e233677
Hope it helps.

Mehmet Ceylan
Mehmet Ceylan el 3 de Jun. de 2024
hello, how do I access the data in .dat format? also is there any chance to include this in the code you wrote, I have never read about the dat file.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by