Create a String Array
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Anas Khan
am 5 Dez. 2020
Kommentiert: Anas Khan
am 5 Dez. 2020
I am trying to create a string array of elements ranging from A1 to H12, where the first 12 elements are A1 - H1, next 12 are A2 - H2 and so on. I want to do this without having to type these out in a comma separated list. Here is my failed attempt at programming this.
Rows = {'A','B','C','D','E','F','G','H'};
Cols = [1:1:12];
wellNames = NaN(1,96);
count = 1;
for y = Cols
ystr = sprintf('%d', y);
for x = Rows
tempstr = num2str(cell2mat([x, ystr]));
wellNames(:,count) = tempstr;
count = count + 1;
end
end
0 Kommentare
Akzeptierte Antwort
Steven Lord
am 5 Dez. 2020
Like this?
c = 'A':'E'
s = string(c')
M = s + (1:6)
4 Kommentare
Steven Lord
am 5 Dez. 2020
To change the shape of an array you can use reshape.
c = 'A':'E';
s = string(c');
M = s + (1:6);
rv = reshape(M, 1, [])
cv = reshape(M, [], 1)
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!