Matlab 3D matrix same index condition

조회 수: 11 (최근 30일)
katarado
katarado 2017년 5월 6일
편집: katarado 2017년 5월 6일
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에서 Matrix Indexing에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by