how to concatenate vectors

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 Comments

Sam - what are the T{k}? Are they scalars, vectors, matrices, strings or ..??
Sorry, I forgot to mention. they are vectors.

Sign in to comment.

 Accepted Answer

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{:})

More Answers (1)

Jan
Jan on 3 May 2015
Edited: Jan on 3 May 2015
When the size of the elements of T are not matching, you can use: FEX: Cell2Vec

Categories

Asked:

on 3 May 2015

Edited:

Jan
on 3 May 2015

Community Treasure Hunt

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

Start Hunting!