How to separate the field from a structure in MATLAB?
27 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
SUSHMA MB
el 3 de Oct. de 2016
I have a structure which is attached with this file named as 'shape.mat'. The structure contains the following fields: Geometry Boundary X Y...etc Now i want to separate X and Y field from the structure and store it in a cell named x_constraint and y_constraint respectively. Can it be done?
2 comentarios
Siva Priya Bollineni
el 21 de Sept. de 2020
Editada: Siva Priya Bollineni
el 21 de Sept. de 2020
@Stephen Cobeldick, I have a matlab file in which i have a class with 4 properties out of which one is a structure with different fields in it. I need to call this matlab file from python through Matlab API engine.
1.Can you please let me know how to access those fields present in that structure of matlab file from python, (when runned the matlab file from python).
2. Also, is there anyway to access the uint64 type data of matlab in to python.
Please someone let me know about this, Thanks in advance.
Respuesta aceptada
michio
el 4 de Oct. de 2016
Editada: michio
el 4 de Oct. de 2016
Your structure seems to be a nonscalar structure, so try using curly bracket:
load('shape.mat');
x_constraint = {S.X};
y_constraint = {S.Y};
4 comentarios
michio
el 4 de Oct. de 2016
One way is to use arrayfun, which applies function to each element of array, in this case, function @(struct) [struct.X; struct.Y] is applied to the each element of a structure S.
load('shape.mat');
AllCell = arrayfun(@(struct) [struct.X; struct.Y], S, 'UniformOutput',false);
Más respuestas (2)
Guillaume
el 3 de Oct. de 2016
Well, unless I completely misunderstood your question:
x_constraint = yourstructure.X;
y_constraint = yourstructure.Y;
However, there is no benefit to that. Why not use yourstructure.X whenever you want x_constraint and not bother creating x_constraint in the first place?
1 comentario
Dimas Rizky
el 29 de Nov. de 2020
Just type :
x_constraint = shape.X(:,1);
y_constraint = shape.Y(:;1);
I hope it's working for you..
0 comentarios
Ver también
Categorías
Más información sobre Structures en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!