Dears,
T is a vector concatenated from T{J} (J=0:4000) which T{1}, T{2}, ... are not same size. How can I concatenate T as a vector?
Regards

2 commentaires

Geoff Hayes
Geoff Hayes le 3 Mai 2015
Sam - what are the T{k}? Are they scalars, vectors, matrices, strings or ..??
Sam sanati
Sam sanati le 3 Mai 2015
Sorry, I forgot to mention. they are vectors.

Connectez-vous pour commenter.

 Réponse acceptée

Jos (10584)
Jos (10584) le 3 Mai 2015

3 votes

If all elements of T are row or column vectors, you can use VERTCAT or HORZCAT, using comma-separated list expansion:
T1 = {[1;2;3],[4],[5;6;7]} % all column vectors
V1 = vertcat(T1{:}) % single column
T2 = {[1 2 3],[4],[5 6 7]} % all row vectors
V2 = horzcat(T2{:}) % single row
For mixed types it will not work directly and you'll have to reshape them first
T3 = {[1;2;3],[4 5],[6 7]} % mixed type
T3c = cellfun(@(x) reshape(x,[],1), T3,'un',0) ; % convert to column vectors first
V3 = vertcat(T3c{:})

Plus de réponses (1)

Jan
Jan le 3 Mai 2015
Modifié(e) : Jan le 3 Mai 2015

0 votes

When the size of the elements of T are not matching, you can use: FEX: Cell2Vec

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by