Hi, I have a matrix ,say A=[1 0 0;0 1 0; 1 0 0] ; I Want to change the value of the first column where I have '1' with 01 & 10 respectively. Is it possible? TIA

1 view (last 30 days)
A=[1 0 0;0 1 0; 1 0 0] ;
I Want to change the value of the first column where I have '1' with 01 & 10 respectively. Is it possible?

Accepted Answer

Walter Roberson
Walter Roberson on 25 Sep 2017
replacements = {[1 0], [0 1]}; %or {'10', '01'}
result = replacements(1+A);
This will give a cell array of values. A cell array is required if you need to preserve the leading '0' of '01': if you were to use
replacements = [10 01];
then
>> replacements(1+A)
ans =
1 10 10
10 1 10
1 10 10

More Answers (0)

Categories

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

Community Treasure Hunt

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

Start Hunting!