Clear Filters
Clear Filters

How to replace matrix element value with predetermined value?

1 view (last 30 days)
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.

Accepted Answer

Andrei Bobrov
Andrei Bobrov on 13 Dec 2011
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 Comment
Ayesa
Ayesa on 13 Dec 2011
Many thanks. The second solution works perfectly and it's also easy to understand. Many thanks for your help.

Sign in to comment.

More Answers (0)

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!