Borrar filtros
Borrar filtros

How to replace repeating values for each column by NaN?

2 visualizaciones (últimos 30 días)
Markus Niemelä
Markus Niemelä el 21 de Mzo. de 2022
Comentada: Markus Niemelä el 24 de Mzo. de 2022
Hi!
I am a Matlab newbie, and I have a problem replacing repeating values for each column.
For example: Let's say I have matrix:
1 2 3 4
2 3 4 4
3 1 3 1
3 1 3 2
And the desired output would then be:
1 2 3 4
2 3 4 NaN
3 1 3 1
NaN NaN NaN 2
Hope this makes sense,
Kr, Markus

Respuesta aceptada

Jan
Jan el 21 de Mzo. de 2022
Editada: Jan el 21 de Mzo. de 2022
A = [1 2 3 4; ...
2 3 4 4; ...
3 1 3 1; ...
3 1 3 2];
M = [false(1, width(A)); diff(A, 1) == 0];
A(M) = NaN
A = 4×4
1 2 3 4 2 3 4 NaN 3 1 3 1 NaN NaN NaN 2

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by