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 visualizzazione (ultimi 30 giorni)
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?

Risposta accettata

Walter Roberson
Walter Roberson il 25 Set 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

Più risposte (0)

Categorie

Scopri di più su Matrices and Arrays in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by