我在一些天气数据上使用for循环来指示雷暴情况的严重性,请参见下面的代码。我现在想知道,如果我用imagesc()显示图像,有没有一种方法可以通过单击像素来显示为什么赋值这个值?例如,如果我单击值为1的像素,它会显示一个文本框,上面写着“因为10 < cape < 750,剪切< 20”谢谢!
for i = 1:size(cape_fin,1)
for j = 1:size(cape_fin,2)
if cape_fin(i,j) > 10 && cape_fin(i,j) < 750 && shear_fin(i,j) < 20
hail_prob_level_fin(i,j) = 1;
elseif cape_fin(i,j) > 10 && cape_fin(i,j) < 750 && shear_fin(i,j) > 20 && shear_fin(i,j) < 40
hail_prob_level_fin(i,j) = 2;
elseif cape_fin(i,j) > 10 && cape_fin(i,j) < 750 && shear_fin(i,j) > 40
hail_prob_level_fin(i,j) = 3;
elseif cape_fin(i,j) > 750 && cape_fin(i,j) < 1300 && shear_fin(i,j) > 20 && shear_fin(i,j) < 40 && tlr_600_800_fin(i,j) < 6.6 || tlr_500_700_fin(i,j) < 7.3
hail_prob_level_fin(i,j) = 2;
elseif cape_fin(i,j) > 750 && cape_fin(i,j) < 1300 && shear_fin(i,j) > 20 && shear_fin(i,j) < 40 && tlr_600_800_fin(i,j) > 6.6 || tlr_500_700_fin(i,j) > 7.3
hail_prob_level_fin(i,j) = 3;
elseif cape_fin(i,j) > 750 && cape_fin(i,j) < 1300 && shear_fin(i,j) > 40 && tlr_600_800_fin(i,j) < 6.6 || tlr_500_700_fin(i,j) < 7.3
hail_prob_level_fin(i,j) = 3;
elseif cape_fin(i,j) > 750 && cape_fin(i,j) < 1300 && shear_fin(i,j) > 40 && tlr_600_800_fin(i,j) > 6.6 || tlr_500_700_fin(i,j) > 7.3
hail_prob_level_fin(i,j) = 4;
elseif cape_fin(i,j) > 750 && cape_fin(i,j) < 1300 && shear_fin(i,j) < 20 && tlr_600_800_fin(i,j) > 7.3 || tlr_500_700_fin(i,j) > 7.9
hail_prob_level_fin(i,j) = 3;
elseif cape_fin(i,j) > 750 && cape_fin(i,j) < 1300 && shear_fin(i,j) < 20 && tlr_600_800_fin(i,j) < 7.3 || tlr_500_700_fin(i,j) < 7.9
hail_prob_level_fin(i,j) = 2;
elseif cape_fin(i,j) > 1300 && cape_fin(i,j) < 2000 && shear_fin(i,j) > 40 && tlr_600_800_fin(i,j) > 6.6 || tlr_500_700_fin(i,j) > 7.3
hail_prob_level_fin(i,j) = 4;
elseif cape_fin(i,j) > 1300 && cape_fin(i,j) < 2000 && shear_fin(i,j) > 40 && tlr_600_800_fin(i,j) < 6.6 || tlr_500_700_fin(i,j) < 7.3
hail_prob_level_fin(i,j) = 3;
elseif cape_fin(i,j) > 1300 && cape_fin(i,j) < 2000 && shear_fin(i,j) > 20 && shear_fin(i,j) < 40 && tlr_600_800_fin(i,j) < 7.3 || tlr_500_700_fin(i,j) < 7.9
hail_prob_level_fin(i,j) = 3;
elseif cape_fin(i,j) > 1300 && cape_fin(i,j) < 2000 && shear_fin(i,j) > 20 && shear_fin(i,j) < 40 && tlr_600_800_fin(i,j) > 7.3 || tlr_500_700_fin(i,j) > 7.9
hail_prob_level_fin(i,j) = 3;
elseif cape_fin(i,j) > 1300 && cape_fin(i,j) < 2000 && shear_fin(i,j) < 20
hail_prob_level_fin(i,j) = 3;
elseif cape_fin(i,j) > 2000 && shear_fin(i,j) > 40 && tlr_600_800_fin(i,j) > 6.6 || tlr_500_700_fin(i,j) > 7.3
hail_prob_level_fin(i,j) = 5;
elseif cape_fin(i,j) > 2000 && shear_fin(i,j) > 40 && tlr_600_800_fin(i,j) < 6.6 || tlr_500_700_fin(i,j) < 7.3
hail_prob_level_fin(i,j) = 4;
elseif cape_fin(i,j) > 2000 && shear_fin(i,j) > 20 && shear_fin(i,j) < 40 && tlr_600_800_fin(i,j) < 7.3 || tlr_500_700_fin(i,j) < 7.9
hail_prob_level_fin(i,j) = 4;
elseif cape_fin(i,j) > 2000 && shear_fin(i,j) > 20 && shear_fin(i,j) < 40 && tlr_600_800_fin(i,j) > 7.3 || tlr_500_700_fin(i,j) > 7.9
hail_prob_level_fin(i,j) = 4;
elseif cape_fin(i,j) > 2000 && shear_fin(i,j) < 20
hail_prob_level_fin(i,j) = 4;
else
hail_prob_level_fin(i,j) = 1;
end
end
end发布于 2019-06-20 23:19:32
下面是一个简单的起点示例:
这个例子让用户用鼠标选择一个像素。
假设像素坐标为x,y
cape_fin和shear_fin )。hail_prob_level_fin)。请注意,这并不是您所期望的自动机制--您需要以父名的方式来完成它。
下面是一个简化的代码示例:
A = imread('cameraman.tif'); %Assume A is cape_fin
B = imbinarize(A); %Assume B is your hail_prob_level_fin (I used imbinarize for simplicity).
figure;imagesc(B); %Display the image (hail_prob_level_fin in your case).
%[x,y,P] = impixel(); %Mark a one pixel, press and press enter (just an example for marking a pixel).
for i = 1:10
[x,y] = ginput(1); %Let the user select a pixel with the mouse.
x = round(x);y = round(y); %Round coordinates.
a = A(y, x); %Get original pixel value (cape_fin in your case, you also need value from shear_fin)
b = B(y, x); %Get result pixel value (hail_prob_level_fin in your case).
%Show message box according to value of original and result pixel value:
waitfor(msgbox(sprintf('B(%d, %d) = %d, because A(%d, %d) = %d', x, y, b, x, y, a)));
end显示消息的示例:

https://stackoverflow.com/questions/56688320
复制相似问题