Effacer les filtres
Effacer les filtres

matrix replacement as string

1 vue (au cours des 30 derniers jours)
Sharen H
Sharen H le 22 Oct 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

Réponse acceptée

Andrei Bobrov
Andrei Bobrov le 22 Oct 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;

Plus de réponses (1)

Andreas Goser
Andreas Goser le 22 Oct 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.

Catégories

En savoir plus sur Multidimensional Arrays dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by