Borrar filtros
Borrar filtros

Structure to matrix

3 visualizaciones (últimos 30 días)
Anna
Anna el 24 de Abr. de 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 comentario
Walter Roberson
Walter Roberson el 24 de Abr. de 2012
Please show the call you tried for struct2cell()

Iniciar sesión para comentar.

Respuesta aceptada

Andrei Bobrov
Andrei Bobrov el 24 de Abr. de 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

Más respuestas (0)

Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by