deal array contents into cell arrays
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Gabriel Stanley
il 9 Dic 2022
Modificato: Stephen23
il 10 Dic 2022
I'm trying to figure out how to assign the values of an array to targeted cell arrays. E.g. I have a 16x6 cell array, and I want to distribute the 32 values of a 16x2 string array into the first two column of the cell, i.e CellArray{1,1} = StringArray(1,1), CellArray{16,2} = String(16,2), etc.
Given that I cannot know the size of the arrays a priori, do I need to figure out an annonymous function using deal to convert the MxN string array into M*N string scalars?
1 Commento
Szemis
il 9 Dic 2022
The task is much easier if you can convert your string array into a cell array.
% a simple example
m = 16;
n = 4;
o = 2;
CellArray = cell(m,n);
String = strings(m,o);
cArr = num2cell(String);
[CellArray{1:m*o}] = cArr{:};
Risposta accettata
Stephen23
il 9 Dic 2022
Modificato: Stephen23
il 9 Dic 2022
C = cell(3,2)
S = ["cat","hat";"hello","world";"A","B"]
[C{:}] = deal(S{:})
2 Commenti
Stephen23
il 10 Dic 2022
Modificato: Stephen23
il 10 Dic 2022
"I cannot tell from either of the linked articles how to go about performing this kind of assignment in the generic case."
As my tutorial clearly states, comma-separated lists can be constructed from three particular data types. There is no "generic case" that applies to all data types.
Of course there is nothing stopping you from creating a cell array of data and using normal parenthesis indexing to assign it to the LHS cell array:
LHScellarray(:) = RHScellarray
This is completely unrelated to comma-separated lists.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Cell Arrays in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!