concatenate all cells in a celll array
Mostrar comentarios más antiguos
hello i have a cell array 7x7
Columns 1 through 6
[256x1 double] [256x1 double] [256x1 double] [256x1 double] [256x1 double] [256x1 double]
[256x1 double] [256x1 double] [256x1 double] [256x1 double] [256x1 double] [256x1 double]
[256x1 double] [256x1 double] [256x1 double] [256x1 double] [256x1 double] [256x1 double]
[256x1 double] [256x1 double] [256x1 double] [256x1 double] [256x1 double] [256x1 double]
[256x1 double] [256x1 double] [256x1 double] [256x1 double] [256x1 double] [256x1 double]
[256x1 double] [256x1 double] [256x1 double] [256x1 double] [256x1 double] [256x1 double]
[256x1 double] [256x1 double] [256x1 double] [256x1 double] [256x1 double] [256x1 double]
Column 7
[256x1 double]
[256x1 double]
[256x1 double]
[256x1 double]
[256x1 double]
[256x1 double]
[256x1 double]
I want to concatenate all t he cells in this cell array to a 7x7x256=12544x1 vector how do i do that ?
Respuesta aceptada
Más respuestas (1)
Azzi Abdelmalek
el 17 de Jul. de 2016
Editada: Azzi Abdelmalek
el 17 de Jul. de 2016
a=arrayfun(@(x) rand(256,1),ones(7),'un',0)
out=reshape(cell2mat(a),[],1)
3 comentarios
Image Analyst
el 17 de Jul. de 2016
Thanks Azzi, I knew there had to be a way.
I think the original poster should not even have used a cell array in the first place. Since all cell contents were double arrays, he should have just used a simple numerical matrix and not mess around with cell arrays.
Azzi Abdelmalek
el 17 de Jul. de 2016
Image Analyste I don't understand the thanks for what? but I agree with you that some choices are really incomprehensible!
Image Analyst
el 17 de Jul. de 2016
Well, you used reshape() and I did the "for" loop. While a for loop might be easier for beginners to understand, reshape() is possibly the more "MATLAB-ish" way to do it. And it can be complicated/confusing to figure out when to use brackets, braces, and parentheses with cell arrays, even for us experienced people that's why I recommend beginners to avoid them if they can.
Categorías
Más información sobre Logical en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!