Why is NaN inserted in wrong position?
Ältere Kommentare anzeigen
I have a matrix
b = [1 3 0;-2 -1 5]
b =
1 3 0
-2 -1 5
When I perform the following operation
b(b(:,3)==5) = NaN;
the NaN is placed a the postion of -2. How come?
1 Kommentar
Dyuman Joshi
am 17 Aug. 2023
Bearbeitet: Dyuman Joshi
am 17 Aug. 2023
"the NaN is placed a the postion of -2. How come?"
Are you sure about that? The output from the code says otherwise -
b = [1 3 0;-2 -1 5];
b(b(1,:)==5) = NaN
No element in the 1st row of b equals to 5, so no assignment will take place.
Akzeptierte Antwort
Weitere Antworten (1)
b = [1 3 0;-2 -1 5];
b(b(:,3)==5,3) = NaN % add ,3 to select only the third column for assignment
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!