フィルターのクリア

matrix replacement as string

1 回表示 (過去 30 日間)
Sharen H
Sharen H 2012 年 10 月 22 日
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

採用された回答

Andrei Bobrov
Andrei Bobrov 2012 年 10 月 22 日
shar = [1 2 3;
1 3 4;
1 4 5];
REP = repmat('v',3,1);
sharcell = num2cell(shar);
REPcell = cellstr(REP);
sharcell(:,1) = REPcell;

その他の回答 (1 件)

Andreas Goser
Andreas Goser 2012 年 10 月 22 日
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.

カテゴリ

Help Center および File ExchangeMultidimensional Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by