If Else Statement in For Loop
2 ビュー (過去 30 日間)
古いコメントを表示
Hello, I have a 1440,721,40 matrix called mag_strength. The first dimension is longitude, the second is latitude, and the third represents 40 time steps of data. I'm trying to create a for loop with an if / else statement embedded that will look at all the data at each time step of the 3rd dimension and keep all values >1 and replace all other values that don't meet the requirement to NaNs. My resulting matrix (of equal size) is named: Fronts. When I run the loop, I get all NaN values, when I know that I should get a mixture of NaNs and positve values greater than 1. Any ideas on what's going on?
Fronts = zeros(1440,721,40);
for F = 1:40
disp(F)
if mag_strength(:,:,F)>1
Fronts(:,:,F) = mag_strength(:,:,F);
else
Fronts(:,:,F) = NaN;
end
end
0 件のコメント
採用された回答
Chunru
2021 年 9 月 3 日
n1 = 6; % 1440
n2 = 4; % 721
n3 = 2; % 40
mag_strength = randn(n1, n1, n3)
Fronts = mag_strength;
Fronts(Fronts<=1) = nan;
Fronts
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Multidimensional Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!