Effacer les filtres
Effacer les filtres

Structure to matrix

3 vues (au cours des 30 derniers jours)
Anna
Anna le 24 Avr 2012
Hello,
I am trying to convert a structure with 40 fields into a single 3D matrix. I tried using struct2cell but got an error ??? Undefined function or method 'struct2cell' for input arguments of type 'double'.
I then tried creating a loop (below) but it writes the first field 40 times instead of writing all 40 fields once.. and I'm not sure how to fix it. The structure (runoff) has 40 fields, each with dimensions 12x360x720. I want to create a matrix (runoff_all) that has all the data in the structure and dimensions 480x360x720. How can I achieve this?
varnames=fieldnames(runoff);
runoff_all=zeros(480,360,720);
for k=1:length(varnames)
for i=1:12:469
runoff_all(i:i+11,:,:)=runoff.(varnames{k})(1:12,:,:);
end
end
  1 commentaire
Walter Roberson
Walter Roberson le 24 Avr 2012
Please show the call you tried for struct2cell()

Connectez-vous pour commenter.

Réponse acceptée

Andrei Bobrov
Andrei Bobrov le 24 Avr 2012
'struct2cell' - built-in function of MATLAB
>> which struct2cell
about loop for .. end
varnames=fieldnames(runoff);
runoff_all=zeros(480,360,720);
for k=1:length(varnames)
frunoff_all(12*k + (-11:0),:,:)=runoff.(varnames{k});
end

Plus de réponses (0)

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!

Translated by