Loading multiple matlab files in to a structure

13 visualizaciones (últimos 30 días)
WellsJ
WellsJ el 2 de Nov. de 2017
Comentada: Stephen23 el 2 de Nov. de 2017
I'm trying to load multiple matlab files in to a structure using
for m = 1:numel(data)
S(m,1) = load(data{m});
end
Where data is the file path. However i have been encountering the following message.
"Subscripted assignment between dissimilar structures."
Any help appreciated
  1 comentario
Rik
Rik el 2 de Nov. de 2017
All your .mat files must contain the same variables, otherwise an error like this is expected. You might try first loading it to a cell to get an idea of what is going wrong (or use breakpoints).

Iniciar sesión para comentar.

Respuesta aceptada

Jos (10584)
Jos (10584) el 2 de Nov. de 2017
This means that the variables are different across files. In a structure array, all the fields should be the same, hence the error. However, the sub-fields can be different!
So, you can use this approach:
for m = 1:numel(data)
S(m,1).content = load(data{m});
end
  2 comentarios
WellsJ
WellsJ el 2 de Nov. de 2017
Perfect! Thanks!
Stephen23
Stephen23 el 2 de Nov. de 2017
Using a cell array would be an alternative.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Structures 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