Maddy
Maddy

Reputation: 363

Concatenation of Vectors in MATLAB

I have these 10 vectors in MATLAB, mean(alltmws{l}'), where l is from 1 to 10. The size of each of these vectors is 1X10001. Now I want to store all these values in one vector, one after the other, so that I can calculate and plot the overall mean. How can I do this concatenation? Any help will be greatly appreciated.

Upvotes: 1

Views: 912

Answers (2)

anon
anon

Reputation:

If you have, for example,

a{1} = rand(10,1);
a{2} = rand(10,1);
a{3} = rand(10,1);

You can do

A = [a{:}];
A = A(:)

EDIT: The question is ambiguous, but if it is the means that one wants to concatenate and plot, you can do:

% Create example data
data = {};
for k = 1:10
  data{k} = rand(100,1);
end

% Compute and plot array of means
mu = []
for k = 1:length(data)
  mu(k) = mean(data{k});
end
plot(mu)

Upvotes: 2

Autonomous
Autonomous

Reputation: 9075

If you have a 1x10 cell array, then you can directly do:

concatnatedArray=cell2mat(yourCellArray);

If you have a 10x1 cell array, first transpose it and then apply above technique. This will only work if all the vectors in each cell are of the same length, which the case for you.

Upvotes: 0

Related Questions