Borrar filtros
Borrar filtros

convert struct field in cell array

2 visualizaciones (últimos 30 días)
Doctor G
Doctor G el 19 de Abr. de 2016
Editada: James Tursa el 20 de Abr. de 2016
I used a json converter which created a 1x15 cell array (see below) that has a field called objectClass (which is a 1x1 struct with one field (objectCalss.objtype) (a number)
I would like to flatten that one field so that objecClass is not a struct, but the number itself.
A picture is worth a 1,000 words...

Respuestas (1)

James Tursa
James Tursa el 19 de Abr. de 2016
Do you mean like this:
for k=1:numel(result.objList)
result.objList(k).objectClass = result.objList(k).objectClass.objtype;
end
  3 comentarios
Doctor G
Doctor G el 20 de Abr. de 2016
(but I am a C, JavaScript, C#, Python programmer), so this is clear to me. What I hear is that there are map and array operations built into matlab, that might be faster than iteration. But thanks again, this is clear.
James Tursa
James Tursa el 20 de Abr. de 2016
Editada: James Tursa el 20 de Abr. de 2016
There may be some function or combination of functions that can do this, but I doubt you would get any significant speed advantages by using them. The reason is you are manipulating fields of structures, which are variables, not elemental values such as elements of a double array. So even if you could use canned MATLAB functions for this, there would probably be looping code of some sort in the background to accomplish the task much like the for loop above (as opposed to some C/C++ code that would give you a speed advantage like you could get by manipulating elements of a double array).

Iniciar sesión para comentar.

Categorías

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

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by