Borrar filtros
Borrar filtros

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

2 visualizaciones (últimos 30 días)
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?

Respuesta aceptada

Walter Roberson
Walter Roberson el 25 de Sept. de 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

Más respuestas (0)

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by