Matlab 3D matrix same index condition
1 view (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
Guillaume
on 6 May 2017
It's not clear what C should be when A is smaller than B.
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 Comments
More Answers (0)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!