User input in a struct

1 visualización (últimos 30 días)
JoeTeg
JoeTeg el 16 de Feb. de 2024
Movida: Dyuman Joshi el 19 de Feb. de 2024
Hello want to implment an Input request befor the following struct so that i will not have to manualy change the maschineType in the struct
motor.winding = struct(...
'windingType', 'distributed' ,... % 'concetrated' , 'distrubuted'
'machineType', 'PMSM',... %'IDM' , PMSM'
'PolePair', 4 ,...
'Number of slots', 60 , ...
'fieldModel', '2D' );
The solution could look like that:
MotorType = input('Enter IDM for induction motor and PMSM for pemanent magnet synchronous motor: ', 's')
motor.winding = struct(...
'windingType', 'distributed' ,... % 'concetrated' , 'distrubuted'
'machineType', 'MotorType',... %'IDM' , PMSM'
'PolePair', 4 ,...
'Number of slots', 60 , ...
'fieldModel', '2D' );
but i have some mistake. How can i do that properly ?
thank you
  3 comentarios
JoeTeg
JoeTeg el 16 de Feb. de 2024
Movida: Dyuman Joshi el 17 de Feb. de 2024
Thank you :)
Walter Roberson
Walter Roberson el 16 de Feb. de 2024
See also menu

Iniciar sesión para comentar.

Respuesta aceptada

Aquatris
Aquatris el 16 de Feb. de 2024
Editada: Aquatris el 16 de Feb. de 2024
You cannot have space in structure field name. And also as @Dyuman Joshi mentioned you should not use quotes when you assign it.
So instead try this:
MotorType = 'xxx'; % replace this with the input command, I use it to demonstrate here
motor.winding = struct(...
'windingType', 'distributed' ,... % 'concetrated' , 'distrubuted'
'machineType', MotorType,... %'IDM' , PMSM'
'PolePair', 4 ,...
'Numberofslots', 60 , ...
'fieldModel', '2D' );
motor.winding
ans = struct with fields:
windingType: 'distributed' machineType: 'xxx' PolePair: 4 Numberofslots: 60 fieldModel: '2D'
Here is the error
MotorType = 'xxx';
motor.winding = struct(...
'windingType', 'distributed' ,... % 'concetrated' , 'distrubuted'
'machineType', MotorType,... %'IDM' , PMSM'
'PolePair', 4 ,...
'Number of slots', 60 , ...
'fieldModel', '2D' );
Error using struct
Invalid field name "Number of slots".
  1 comentario
JoeTeg
JoeTeg el 19 de Feb. de 2024
Movida: Dyuman Joshi el 19 de Feb. de 2024
thanks a lot

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Productos


Versión

R2007b

Community Treasure Hunt

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

Start Hunting!

Translated by