フィルターのクリア

How can I add a char in a matrix?

5 ビュー (過去 30 日間)
jelly
jelly 2012 年 10 月 6 日
コメント済み: Dursun ÖNER 2020 年 5 月 22 日
hey how can I add a string in matrix?
ex.
for i=1:5
A(i)=i+1;
end
mat2str(A);
...
for I want to have to put A or B or C.
I tried this
A(5)='B'
but the output was
1 2 3 4 65.
How could I make it like
1 2 3 4 A
??? please help me :)

回答 (2 件)

Azzi Abdelmalek
Azzi Abdelmalek 2012 年 10 月 6 日
編集済み: Azzi Abdelmalek 2012 年 10 月 7 日
use cell aray
A=[1 2 3 4]
B=[ num2cell(A) 'A']
%or
A=num2cell(A)
A{5}='A'
  5 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2012 年 10 月 7 日
jelly what do you want exactly?
Dursun ÖNER
Dursun ÖNER 2020 年 5 月 22 日
well what do i do if we want to convert 'AA' instead 'A'

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


Matt Fig
Matt Fig 2012 年 10 月 6 日
A = sprintf('%i',1:5); % Make a character array.
A(6) = 'B'
If you must have spaces, then you must be more careful about how you index into A. A character array counts the spaces as elements!
A = sprintf('%i ',1:5);
A(11) = 'B'

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by