Filter löschen
Filter löschen

User input in a struct

5 Ansichten (letzte 30 Tage)
Etienne
Etienne am 16 Feb. 2024
Verschoben: Dyuman Joshi am 19 Feb. 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 Kommentare
Etienne
Etienne am 16 Feb. 2024
Verschoben: Dyuman Joshi am 17 Feb. 2024
Thank you :)
Walter Roberson
Walter Roberson am 16 Feb. 2024
See also menu

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Aquatris
Aquatris am 16 Feb. 2024
Bearbeitet: Aquatris am 16 Feb. 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 Kommentar
Etienne
Etienne am 19 Feb. 2024
Verschoben: Dyuman Joshi am 19 Feb. 2024
thanks a lot

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2007b

Community Treasure Hunt

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

Start Hunting!

Translated by