Concatenation of Vectors in MATLAB

喜夏-厌秋 提交于 2019-12-12 00:18:36

问题


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.


回答1:


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)



回答2:


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.



来源:https://stackoverflow.com/questions/15170467/concatenation-of-vectors-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!