How to create a new matrix from another two matrices

1 Ansicht (letzte 30 Tage)
FAISAL
FAISAL am 2 Jul. 2016
Beantwortet: the cyclist am 2 Jul. 2016
Hi there, i have 2 matrices of image, both have the same number of pixels A(160,700) and B(160,700). So what I want to do is to create a new matrix (C), which uses the same value in B providing the condition in A is met, but replace it to 0 if its not. In A, i have values from 0 to 1. If the value in A is 0.1<A<0.3, so the C uses the same values as in B, otherwise it is 0.
i tried to use this code below, but it does not work
C=zeros(size(A));
for ii = 1:length(A)
if A(ii)<0.1 & A(ii)>0.3
C(ii)=0;
else C(ii)=B(ii)
end
end
Thanks in advance for your help!

Akzeptierte Antwort

the cyclist
the cyclist am 2 Jul. 2016
C=zeros(size(A));
indexToB = A>0.1 & A<0.3
C(indexToB) = B(indexToB)

Weitere Antworten (0)

Kategorien

Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by