フィルターのクリア

How to create a vector?

2 ビュー (過去 30 日間)
Sim
Sim 2012 年 10 月 16 日
Hello everyone, Suppose with a for loop I get an array for each file (array could be of different lengths for each file). I want to get a column vector which will be merging of these arrays. So all the values of arrays from each file will be in this huge vector. Thank you for you help in advance.

採用された回答

Babak
Babak 2012 年 10 月 16 日
編集済み: Babak 2012 年 10 月 16 日
vector=[];
for j=1:n
% find newone that comes from file(j)
vector = [vector , newone]
end
  2 件のコメント
Sim
Sim 2012 年 10 月 16 日
Thank you veru much
Matt Kindig
Matt Kindig 2012 年 10 月 16 日
Keep in mind that if this is a "huge vector", then it might be rather slow due to a lack of memory pre-allocation. I would recommend something like this:
% vector is output from file(j)
r = size(vector,1);
Vector = NaN(r,n); %this is the pre-allocation step-- very important for memory management/efficiency!
Vector(:,1)=vector;
for j=2:n,
%newone comes from file(j)
Vector(:,j) = newone;
end

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by