Replacing whole row with NaN's if first value is equal to 13 or 15.

1 view (last 30 days)
Hi! I have a matrix in which I want to replace the whole row with NaNs if the value of the first row is equal to 13 of 15. Can anyone help me with this?

Accepted Answer

Voss
Voss on 19 Jun 2022
Do you mean the value of the first column is equal to 13 or 15?
A = randi(20,10,5)
A = 10×5
1 1 3 2 20 15 14 17 19 10 14 14 11 19 9 1 9 1 4 18 4 8 2 16 19 19 17 10 4 19 11 1 20 5 1 13 1 6 14 9 8 7 13 10 14 12 9 8 7 4
idx = A(:,1) == 13 | A(:,1) == 15;
A(idx,:) = NaN
A = 10×5
1 1 3 2 20 NaN NaN NaN NaN NaN 14 14 11 19 9 1 9 1 4 18 4 8 2 16 19 19 17 10 4 19 11 1 20 5 1 NaN NaN NaN NaN NaN 8 7 13 10 14 12 9 8 7 4
Or do you mean replace the whole column if the value of the first row is 13 or 15?
A = randi(20,10,5)
A = 10×5
18 13 10 1 6 8 15 5 7 18 13 4 12 18 3 2 17 6 17 10 6 16 8 10 15 3 11 13 14 7 12 2 13 14 8 13 20 15 1 2 12 4 11 6 18 11 15 1 11 11
idx = A(1,:) == 13 | A(1,:) == 15;
A(:,idx) = NaN
A = 10×5
18 NaN 10 1 6 8 NaN 5 7 18 13 NaN 12 18 3 2 NaN 6 17 10 6 NaN 8 10 15 3 NaN 13 14 7 12 NaN 13 14 8 13 NaN 15 1 2 12 NaN 11 6 18 11 NaN 1 11 11

More Answers (0)

Community Treasure Hunt

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

Start Hunting!