replace a double in a array with a string BUT in specific Columns?

2 ビュー (過去 30 日間)
Yufei Cao
Yufei Cao 2018 年 10 月 20 日
コメント済み: madhan ravi 2018 年 10 月 23 日
Suppose the matrix is
A = [ 0.5 2 3 2.5 1 1
0.6 1 2 2.4 2 3
0.2 2 3 2.3 3 2]
My question is to replace 1 with so-so, 2 with Bad and 3 with good in 2nd and 3rd columns, and 1 with so-so, 2 with Bad and 3 with good in 5th and 6th column. I try to use num2cell, but cannot find out the way.
The output looks like this:
A = [ 0.5 bad good 2.5 so-so so-so
0.6 so-so bad 2.4 bad good
0.2 bad good 2.3 good bad]

採用された回答

madhan ravi
madhan ravi 2018 年 10 月 20 日
編集済み: madhan ravi 2018 年 10 月 20 日
>> AA = string([ 0.5 2 3 2.5 1 1
        0.6 1 2 2.4 2 3
        0.2 2 3 2.3 3 2])
    A = strrep(AA(:,[2 3 5 6]),'1','so-so');
    A = strrep(A(:,1:4),'2','bad');
    A = strrep(A(:,1:4),'3','good');
    AA(:,[2 3 5 6])=A;
   A=AA
AA = 
    3×6 string array
      "0.5"    "2"    "3"    "2.5"    "1"    "1"
      "0.6"    "1"    "2"    "2.4"    "2"    "3"
      "0.2"    "2"    "3"    "2.3"    "3"    "2"
A = 
    3×6 string array
      "0.5"    "bad"      "good"    "2.5"    "so-so"    "so-so"
      "0.6"    "so-so"    "bad"     "2.4"    "bad"      "good" 
      "0.2"    "bad"      "good"    "2.3"    "good"     "bad"  
>> 
  6 件のコメント
Yufei Cao
Yufei Cao 2018 年 10 月 23 日
it works well. thanks
madhan ravi
madhan ravi 2018 年 10 月 23 日
Anytime :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by