double array of 0's and 1's conversion help
Mostrar comentarios más antiguos
I have an array of 0's and 1's
Im trying to convert the 0's to nans and 1's to another value.
A(find(A==1)=256; %this part works
A(find(A==0)=NaN; %this part doesn't
when i try to replace the 0's, it replaces everything in the array with NaN, even though find(A==0) does return only the indices of where that array has a 0 value.
is there technical thing I'm missing here?
Respuestas (2)
Walter Roberson
el 20 de Jun. de 2012
A(A==1) = 256;
A(A==0) = NaN;
If you want to live a life of confusion, and you only have 0 and 1s in the matrix,
A = A ./ A * 256;
4 comentarios
the cyclist
el 20 de Jun. de 2012
Walter, I recognize that your syntax avoids the unnecessary find(), but what's the use case in which your syntax works, but David's doesn't? I'm puzzled.
Tom
el 20 de Jun. de 2012
He may have left the bracket off like in the question?
Walter Roberson
el 20 de Jun. de 2012
Reduces the steps that can go wrong ?
David C
el 20 de Jun. de 2012
David C
el 20 de Jun. de 2012
2 comentarios
Sean de Wolski
el 20 de Jun. de 2012
What happens if you run this:
A = double(rand(10)>0.5);
A(A==1) = 256;
A(A==0) = NaN;
A
Walter Roberson
el 20 de Jun. de 2012
Try breaking it down and do some experiments to see which step is going wrong:
A
T = A == 0
B = A;
A(T) = NaN
B(1) = NaN
C = rand(size(A));
C(T) = NaN
Categorías
Más información sobre Logical en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!