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

1 view (last 30 days)
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]

Accepted Answer

Image Analyst
Image Analyst on 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;

More Answers (0)

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by