- Either modify your expression for a so that contours are generated with matching values of x-ticks, or
- You can change the x-ticks to match the contour data points.
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 次查看(过去 30 天)
显示 更早的评论
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")
0 个评论
回答(2 个)
Vishwa
2023-2-27
编辑:Vishwa
2023-2-27
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:
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.
0 个评论
Mehmet Ceylan
2024-6-3
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!