How can I add a char in a matrix?

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일

0 개 추천

use cell aray
A=[1 2 3 4]
B=[ num2cell(A) 'A']
%or
A=num2cell(A)
A{5}='A'

댓글 수: 5

jelly
jelly 2012년 10월 6일
thanks man, this would work but, I need to convert this to str so I can use strcat().. and now im wondering about that.
Matt J
Matt J 2012년 10월 6일
편집: Matt J 2012년 10월 6일
[A+'0','A']
or
[num2str(A), ' A']
jelly
jelly 2012년 10월 6일
with a triple space? in num2str?
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일

0 개 추천

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'

카테고리

도움말 센터File Exchange에서 Data Type Identification에 대해 자세히 알아보기

태그

질문:

2012년 10월 6일

댓글:

2020년 5월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by