How to change to nan values in one matrix based on another logical matrix?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Ekaterina Serikova
am 10 Jun. 2016
Kommentiert: Ekaterina Serikova
am 10 Jun. 2016
Dear MatLab experts,
I have two matrixes: "First" (24 000 by 915) and "Second" (24 000 by 915). "First" consists of different numbers, "second" consists of values 1 or 0. How can I change only those values in matrix "first" to NaN, which correspond to zeros in "second" matrix?
When I try to do First(second)=nan, I get the reverse results from what I need - MatLab leaves the values for zero values, but puts NaN for ones..
Thanks a lot for your help, Ekaterina
0 Kommentare
Akzeptierte Antwort
Geoff Hayes
am 10 Jun. 2016
Ekaterina - if you want those values in the first matrix to be set to NaN if the corresponding value in the second matrix is zero, then you could do something like
A = [1 2 ; 3 4];
B = [1 0 ; 0 1];
A(~B) = NaN;
which gives us
A =
1 NaN
NaN 4
as expected.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical 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!