【发布时间】:2015-12-15 16:21:17
【问题描述】:
使用大小为 20x30 的地理网格,我有两个(温度)变量:
数据A,大小为20x30x100
和一个 threshold 大小为 20x30
我想将阈值应用于数据,即删除A 中高于threshold 的值,每个网格点都有自己的阈值。由于这将为每个网格点提供不同数量的值,因此我想用零填充其余部分,以便生成的变量(我们称之为 B)也将具有 20x30x100 的大小。
我正在考虑做这样的事情,但循环有问题:
B = sort(A,3); %// sort third dimension in ascending order
threshold_3d = repmat(threshold,1,1,100); %// make threshold into same size as B
for i=1:20
for j=1:30
if B(i,j,:) > threshold_3d(i,j,:); %// if B is above threshold
B(i,j,:); %// keep values
else
B(i,j,:) = 0; %// otherwise set to zero
end
end
end
执行循环的正确方法是什么?
还有什么其他选择可以做到这一点?
感谢您的帮助!
【问题讨论】:
标签: matlab multidimensional-array threshold temperature