Borrar filtros
Borrar filtros

matrix replacement as string

1 visualización (últimos 30 días)
Sharen H
Sharen H el 22 de Oct. de 2012
I have got two matrix one has the value
shar = [1 2 3
1 3 4
1 4 5]
other matrix has the value
REP=[v
v
v]
i want to replace the first row of shar using REP
I tried this code shar(:,1) = REP(:,1); it gets replaced as 118 instead of string 'v'.Help me Thanks in advance

Respuesta aceptada

Andrei Bobrov
Andrei Bobrov el 22 de Oct. de 2012
shar = [1 2 3;
1 3 4;
1 4 5];
REP = repmat('v',3,1);
sharcell = num2cell(shar);
REPcell = cellstr(REP);
sharcell(:,1) = REPcell;

Más respuestas (1)

Andreas Goser
Andreas Goser el 22 de Oct. de 2012
There are a couple of obstacles... In your examplex, the 'v' inside 'REP' is not a string (AKA character array). MATLAB expects a variable called 'v' and looks for its content. And even if REP would be a character array, you couldn't mix it with the DOUBLE valueas from 'shar'.
Depending on you appliation, you might use characters only, or a cell array.

Categorías

Más información sobre Multidimensional Arrays en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by