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!