Azzera filtri
Azzera filtri

matrix replacement as string

1 visualizzazione (ultimi 30 giorni)
Sharen H
Sharen H il 22 Ott 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

Risposta accettata

Andrei Bobrov
Andrei Bobrov il 22 Ott 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;

Più risposte (1)

Andreas Goser
Andreas Goser il 22 Ott 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.

Categorie

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

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by