Matlab 3D matrix same index condition

8 Ansichten (letzte 30 Tage)
katarado
katarado am 6 Mai 2017
Bearbeitet: katarado am 6 Mai 2017
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

Akzeptierte Antwort

Guillaume
Guillaume am 6 Mai 2017
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

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by