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 :)

Antworten (2)

Azzi Abdelmalek
Azzi Abdelmalek am 6 Okt. 2012
Bearbeitet: Azzi Abdelmalek am 7 Okt. 2012

0 Stimmen

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

5 Kommentare

jelly
jelly am 6 Okt. 2012
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 am 6 Okt. 2012
Bearbeitet: Matt J am 6 Okt. 2012
[A+'0','A']
or
[num2str(A), ' A']
jelly
jelly am 6 Okt. 2012
with a triple space? in num2str?
Azzi Abdelmalek
Azzi Abdelmalek am 7 Okt. 2012
jelly what do you want exactly?
Dursun ÖNER
Dursun ÖNER am 22 Mai 2020
well what do i do if we want to convert 'AA' instead 'A'

Melden Sie sich an, um zu kommentieren.

Matt Fig
Matt Fig am 6 Okt. 2012

0 Stimmen

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'

Gefragt:

am 6 Okt. 2012

Kommentiert:

am 22 Mai 2020

Community Treasure Hunt

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

Start Hunting!

Translated by