How to convert a cell containing sub cells to a vector

1 vue (au cours des 30 derniers jours)
CSCh
CSCh le 14 Jan 2021
Commenté : CSCh le 14 Jan 2021
Hi, I have a cell
A (1x2 cell array) containing e.g. {1x5}cell {1x3} cell
1×5 cell array
{142×1 cell} {113×1 cell} {112×1 cell} {84×1 cell} {111×1 cell}
1×3 cell array
{108×1 cell} {103×1 cell} {105×1 cell}
but the size variates.Filled only with values.
I want to convert it to a Vector (double).
Thanks in advanced.

Réponse acceptée

Matt J
Matt J le 14 Jan 2021
Modifié(e) : Matt J le 14 Jan 2021
A={{{rand(5,1)},{rand(7,1)}},{rand(3,1)}}; %Example
Vector=A;
while iscell(Vector)
Vector=cellfun(@(c) c(:), Vector,'uni',0);
Vector=vertcat(Vector{:});
end
Vector
Vector = 15×1
0.7374 0.7479 0.3791 0.8229 0.8585 0.6092 0.1645 0.9843 0.9996 0.3845
  1 commentaire
CSCh
CSCh le 14 Jan 2021
This works excellent, many thanks!!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Data Type Conversion dans Help Center et File Exchange

Produits


Version

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by