Effacer les filtres
Effacer les filtres

How can I add a char in a matrix?

5 vues (au cours des 30 derniers jours)
jelly
jelly le 6 Oct 2012
Commenté : Dursun ÖNER le 22 Mai 2020
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 :)

Réponses (2)

Azzi Abdelmalek
Azzi Abdelmalek le 6 Oct 2012
Modifié(e) : Azzi Abdelmalek le 7 Oct 2012
use cell aray
A=[1 2 3 4]
B=[ num2cell(A) 'A']
%or
A=num2cell(A)
A{5}='A'
  5 commentaires
Azzi Abdelmalek
Azzi Abdelmalek le 7 Oct 2012
jelly what do you want exactly?
Dursun ÖNER
Dursun ÖNER le 22 Mai 2020
well what do i do if we want to convert 'AA' instead 'A'

Connectez-vous pour commenter.


Matt Fig
Matt Fig le 6 Oct 2012
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'

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by