Efficient way to assign single vectors to a cell array

2 ビュー (過去 30 日間)
Pietro Murialdo
Pietro Murialdo 2019 年 10 月 20 日
コメント済み: Pietro Murialdo 2019 年 10 月 20 日
Hello everybody,
I have M vectors, each one containing N(i) elements [with i = 1:M]; so the length of each vector is variable. I read each vector with a for loop. What I would like to do is creating a cell array, with M cells, where each cell (i) contains NOT a "reference" to the vector, but the N(i) elements of each vector.
This is what I am doing,
monthName = {'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', ...
'Jul', 'Aug', 'Sept', 'Oct', 'Nov', 'Dec'};
for j = 1:length(monthName)
filename = [directory, 'series', monthName{j}, '.mat'];
tmp = load(filename);
whos tmp
rawSeries{j}(:,1) = tmp;
end
And I get (I reported only 2 of 12 outputs),
Name Size Bytes Class Attributes
tmp 1x1 4046744 struct
Name Size Bytes Class Attributes
tmp 1x1 3653128 struct
And the cell array rawSeries is a 1x12 cell, where each cell is a 1x1 struct that contains the N(i)x1 vector. This is not what I want.
I would like rawSeries to be a 1x12 cell array, where each cell contains N(i)x1 vector. So that,
rawSeries{1}(:,1)
rawSeries{2}(:,1)
would print the whole vectors cantained in the first and second cell.
Then if it is possible, I would like to do that in the fastest way since I have very large datasets.
Thank you in advance

採用された回答

Matt J
Matt J 2019 年 10 月 20 日
編集済み: Matt J 2019 年 10 月 20 日
for j = 1:length(monthName)
filename = [directory, 'series', monthName{j}, '.mat'];
S = load(filename);
rawSeries{j}(:,1) = S.whatever; %"whatever" should be the name of the variable in the .mat file
end
  1 件のコメント
Pietro Murialdo
Pietro Murialdo 2019 年 10 月 20 日
Ok thank you very much, I was missing the .whatever and I could not understand

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by