How to replace matrix element value with predetermined value?

1 次查看(过去 30 天)
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