Efficient way to assign single vectors to a cell array

2 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Matt J
Matt J il 20 Ott 2019
Modificato: Matt J il 20 Ott 2019
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

Più risposte (0)

Categorie

Scopri di più su Structures in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by