Matlab 3D matrix same index condition

1 次查看(过去 30 天)
Hello,
Imagine two squared arrays A and B. I want array C to equal array A if array A is >= than array B.
Now, imagine array A is a 3D array. So I would need array C to also be 3D.
My knowledge is really limited, so any thought process (how you came up with the code) is welcome!
This is what I have (but it is not working), what can I change?
for k=1:1:15
for j=1:1:384
for i=1:1:384
if dBZ(i,j,k) >= dBZ_Mask(i,j)
weather(i,j,k) = dBZ(i,j,k);
end
end
end
end

采纳的回答

Guillaume
Guillaume 2017-5-6
It's not clear what C should be when A is smaller than B.
Option 1: C should be B when A is smaller than B. This is trivially achieved with the max function:
C = max(A, B);
Option 2: C should be zero (or another constant) when A is smaller than B. This is easily achieved with some simple comparison and logical indexing:
C = zeros(size(A)); %initialise to constant
C(A>=B) = A(A>=B); %copy values when A >= B

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by