Efficient way to assign single vectors to a cell array
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Pietro Murialdo
le 20 Oct 2019
Commenté : Pietro Murialdo
le 20 Oct 2019
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
0 commentaires
Réponse acceptée
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Structures dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!