Filter löschen
Filter löschen

matrix replacement as string

1 Ansicht (letzte 30 Tage)
Sharen H
Sharen H am 22 Okt. 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

Akzeptierte Antwort

Andrei Bobrov
Andrei Bobrov am 22 Okt. 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;

Weitere Antworten (1)

Andreas Goser
Andreas Goser am 22 Okt. 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.

Kategorien

Mehr zu Multidimensional Arrays finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by