how to convert vector char to matrix char ?
Mostra commenti meno recenti
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 Commento
Stephen23
il 13 Set 2021
Using a cell array for this is pointlessly complex and inefficient.
Using a character array, as Chunru shows, is simpler and more efficient.
Risposta accettata
Più risposte (1)
Awais Saeed
il 13 Set 2021
Modificato: Awais Saeed
il 13 Set 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 Commento
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
Categorie
Scopri di più su Matrix Indexing in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!