필터 지우기
필터 지우기

How to replace repeating values for each column by NaN?

조회 수: 2 (최근 30일)
Markus Niemelä
Markus Niemelä 2022년 3월 21일
댓글: Markus Niemelä 2022년 3월 24일
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

채택된 답변

Jan
Jan 2022년 3월 21일
편집: Jan 2022년 3월 21일
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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by