I got error : Names of fields in structure arrays being concatenated do not match. Concatenation of structure arrays requires that these arrays have the same set of fields.

44 visualizaciones (últimos 30 días)
I have used the following files and the error is :
Error using vertcat Names of fields in structure arrays being concatenated do not match. Concatenation of structure arrays requires that these arrays have the same set of fields.
Error in linearsyntax (line 16) test=[test0;test1];
  3 comentarios
sam  CP
sam CP el 23 de Mzo. de 2017
Error using vertcat Names of fields in structure arrays being concatenated do not match. Concatenation of structure arrays requires that these arrays have the same set of fields.
Error in linearsyntax (line 16) test=[test0;test1];
Image Analyst
Image Analyst el 24 de Mzo. de 2017
What does this show:
fieldnames(NormalMRI);
fieldnames(AbnormalMRI);
If they don't show the same fieldnames, which is what the error is saying, then exactly what are you trying to do?

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 23 de Mzo. de 2017
The return value from load() is a structure with one field for each variable stored in the mat file. Even without opening the mat files I can tell that your code instead expects the return value to be the content of a single variable stored in the mat file. You will need to refer to the appropriate field name of the returned structure.
  8 comentarios
sam  CP
sam CP el 26 de Mzo. de 2017
Editada: sam CP el 26 de Mzo. de 2017
function r = load1(filename)
t = load(filename) ;
f = fieldnames(t) ;
r = t.(f{1});
The code works for my program..Can you explain that how this matlab code works?
Walter Roberson
Walter Roberson el 26 de Mzo. de 2017
The return value from load() is a structure with one field for each variable stored in the mat file. This code does a load() and queries the field names of the resulting structure and picks the first one. It then does dynamic field name referencing to extract the content of the field.
The net result is to return the content of the "first" variable stored in the .mat file.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by