How can I save 3d arrays in a cell array?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Miriã Gollmann
le 16 Juin 2018
Commenté : Walter Roberson
le 16 Juin 2018
I have two 3d arrays (138x155x24) but I can't put it in only cell array. How can I do that?
Thanks for any help!
2 commentaires
James Tursa
le 16 Juin 2018
You certainly can put 3D arrays into a cell array. Please post what variables you have and also post the code you are currently trying, and what you want to get as a result.
Réponse acceptée
Walter Roberson
le 16 Juin 2018
data = cell(1,2);
for K = 1 : 2
data{K} = rand(138, 155, 24);
end
and now data is a cell array with two entries, each containing a 138 x 155 x 24 array.
2 commentaires
Walter Roberson
le 16 Juin 2018
dinfo = dir('*.nc');
nfile = length(dinfo);
data = cell(nfile, 1);
for K = 1 : nfile
thisfile = dinfo(K).name;
data{K} = mat2cell( ncread(thisfile, 'velocity'), 3 ); %split on 3rd dimension
end
This would give you a cell array, data, with one entry per file. Each entry would itself be a cell array of length 24, each containing one lon x lat entry.
Note: you might find that you get lat x lon entries instead of lon x lat. If so then
data{K} = mat2cell( permute(ncread(thisfile, 'velocity'), [2 1 3], 3 ); %split on 3rd dimension
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Data Type Conversion dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!