how to convert vector char to matrix char ?
Afficher commentaires plus anciens
I have a variable X = 'ABCDEFGHIJKLMNOPQRSTWXYZ'
how i can fill it in a matrix with single char in single index
like X(1,1)=A ,X(1,2)=B,X(1,3)=C and so on.
1 commentaire
Stephen23
le 13 Sep 2021
Using a cell array for this is pointlessly complex and inefficient.
Using a character array, as Chunru shows, is simpler and more efficient.
Réponse acceptée
Plus de réponses (1)
Awais Saeed
le 13 Sep 2021
Modifié(e) : Awais Saeed
le 13 Sep 2021
How about using cell?
X = 'ABCDEFGHIJKLMNOPQRSTWXYZ';
v = cellstr(num2cell(X))
By now you use access cells as v{2}, v{4} etc.
v{2}
v{3}
To make a matrix out of it, you can reshape v as
rows = 4;
vr = reshape(v,rows,[])'
And to access elements from row, for example 2
vr{1,3}
1 commentaire
char array is much more efficient than cell array.
X = char('A'+(0:23));
C = reshape(X, [4 6])'
V = cellstr(num2cell(X));
V = reshape(V, 4, [])'
whos % compare the storage space of C and V
Catégories
En savoir plus sur Matrices and Arrays dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!