Borrar filtros
Borrar filtros

Add field to input struct array in Mex

9 visualizaciones (últimos 30 días)
Mark Thomson
Mark Thomson el 21 de Mzo. de 2023
Editada: James Tursa el 4 de Abr. de 2023
Dear All,
I would like to add and populate a new field in an existing struct array.
(Context: I just want to distribute the columns of a matrix into the struct array as vectors, but am seeing performance issues with the usual num2cell -> deal approach)
I had thought to try this in a Mex file, but didn't find any documentation/examples for .c, rather just warnings about input structure/cell arrays being read-only.
Is there a way to do this in a C-based Mex file? Or in a C++-based one? I would prefer to generate the field inside the Mex function, but I guess adding a placeholder for the field in an intermediate m-file function would also be fine.
Regards, MT
  1 comentario
James Tursa
James Tursa el 28 de Mzo. de 2023
Editada: James Tursa el 4 de Abr. de 2023
Please post a small example showing all inputs and desired output. I should warn you, however, that there is no official way to do this efficiently in a mex routine. To do it efficiently in a mex routine requires unofficial hacking into the mxArray structure to create reference copies. Doable, but probably not what you wanted.

Iniciar sesión para comentar.

Respuestas (1)

Swaraj
Swaraj el 4 de Abr. de 2023
In order to add a new field to the struct Array in Mex, you can use “mxAddField” function.
Please go through the following documentation for further details.

Categorías

Más información sobre Write C Functions Callable from MATLAB (MEX Files) en Help Center y File Exchange.

Etiquetas

Productos


Versión

R12.1

Community Treasure Hunt

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

Start Hunting!

Translated by