MATLAB: 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

arraysbinary matrixcellmatrixstrings

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?

Best Answer

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