필터 지우기
필터 지우기

How to replace matrix element value with predetermined value?

조회 수: 1 (최근 30일)
Ayesa
Ayesa 2011년 12월 13일
I have m by n matrix and each element value can be any one of these three number: 0, 48, 49. (I have a code which generates this 3 values).
I want to replace 48 by 0 and 49 by 1. Is there any way to do that?
Thanks.

채택된 답변

Andrei Bobrov
Andrei Bobrov 2011년 12월 13일
A - your array with 0,48,49.
[c c c] = unique(A)
d = [0 0 1]
Aout = A;
Aout(:) = d(c)
or
Aout = zeros(size(A));
Aout(A==49) = 1;
  댓글 수: 1
Ayesa
Ayesa 2011년 12월 13일
Many thanks. The second solution works perfectly and it's also easy to understand. Many thanks for your help.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by