Problem with cell array appending
Mostra commenti meno recenti
mycell is appended with cell arrays in three different areas of my code. Like below
mycell= { }
mycell= A(:,:,1) %1st time. A(:,:,1) is a 1*5 cell array
mycell= {mycell ; B(:,:,1) } %2nd time. B(:,:,1) is a 1*5 cell array
mycell= {mycell ; C(:,:,1) } %3rd time. C(:,:,1) is a 1*5 cell array
1st time output is OK: mycell is a cellarray of 1*5.
2nd time output is also OK: mycell is a 2*1 cell array with each element of 1*5 size.
BUT 3rd time output: mycell is still a 2*1 cell array as below. Why? Why do the previous two elements form as a single element in this third time? Can someone tell me how do I avoid this?
%the output I get after 3rd time line
mycell =
2×1 cell array
{2×1 cell}
{1×5 cell}
% but the output I want is something like.
{1×5 cell}
{1×5 cell}
{1×5 cell}
1 Commento
Stephen23
il 17 Set 2021
Note the difference:
- {} curly braces creates a cell array, where the inputs are nested inside the new cell array.
- [] square brackets are a concatenation operator. These are used to concatenate any array type.
So if you want to nest cell arrays inside other cell arrays, then use curly braces. But if you want to concatenate any arrays together, use square brackets (or the operators CAT, HORZCAT, VERTCAT).
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Matrices and Arrays 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!