How do you turn values in column A to NaN if values in column B are zero?

1 Ansicht (letzte 30 Tage)
If column B is 0 turn column 1 to nan
So, it would turn something like this:
[37370 1
37421 0
25021 1
63453 1
25467 0
36511 0
37341 1
50508 0
28250 1]
Into this:
[37370 1
nan 0
25021 1
63453 1
nan 0
nan 0
37341 1
nan 0
28250 1]

Akzeptierte Antwort

Image Analyst
Image Analyst am 19 Nov. 2021
% If A and B are separate column vector variables:
A(B==0) = nan;
% or for an N-by-2 matrix m
rowsToChange = m(:, 2) == 0;
m(rowsToChange, 1) = nan;

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by