Defining structure as a property of a class

I defined a class having params property like this. (I removed method part)
It works well but then I notice one-line params definition is hard to follow and for description. I tried the commented codes but it did not work. What would you recommend me to do? Thank you in advance.
classdef CartPole
%CARTPOLE Summary of this class goes here
% Detailed explanation goes here
properties
% field1 = 'length'; value1 = 0.6; % [m]
% field2 = 'mCart'; value2 = 0.5; % [kg]
% field3 = 'mPole'; value3 = 0.5; % [kg]
% field4 = 'fric'; value4 = 0.1; % [N/m/s]
% field5 = 'g'; value5 = 9.82; % [m/s2]
% params = struct(field1,value1,field2,value2,field3,value3,field4,value4,field5,value5)
params = struct('length',0.6,'mCart',0.5,'mPole',0.5,'fric',0.1,'g',9.82)
states = [0;0;0;0] % [x (m); dx (m/s); dtheta (rad/s); theta (rad)]
dstates = [0;0;0;0]
end
end

 Réponse acceptée

Matt J
Matt J le 13 Fév 2022
Perhaps as follows?
classdef CartPole
%CARTPOLE Summary of this class goes here
% Detailed explanation goes here
properties
params = struct('length',0.6,... % [m]
'mCart',0.5, ... % [kg]
'mPole',0.5, ... % [kg]
'fric',0.1, ... % [N/m/s]
'g',9.82) % [m/s2]
states = [0;0;0;0] % [x (m); dx (m/s); dtheta (rad/s); theta (rad)]
dstates = [0;0;0;0]
end
end

2 commentaires

Khai Nguyen
Khai Nguyen le 14 Fév 2022
Thank you. This is great.
Matt J
Matt J le 14 Fév 2022
You're very welcome, but please Accept-click the answer to indicate that it addressed your problem.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Enterprise Deployment with MATLAB Production Server dans Centre d'aide et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by