how to extract data from sys=ss(A,B,C,D) that is , inputs and outputs
Show older comments
%State-space representation of the system
A= [-85 250 63];
B= [11 0; 0 11; ];
C=[0 0 1 0 0];
D=[0 0;0 0];
Accepted Answer
More Answers (1)
Let's try this simple state-space model and generate the data using ode45() function (click on the link):

If the input is designed as
, the feedback closed-loop system becomes:

I'm referring to some examples in anfis() documentation. If you find the demo and MATLAB code helpful, please consider voting 👍 the Answer.
[t, y] = ode45(@system, [0 10], [1; 0]);
plot(t, y), grid on, xlabel('t'), ylabel('\bf{y}(t)'), legend('y_1', 'y_2')
% organizing the data
out1 = y(:,1); % position signal
out2 = y(:,2); % velocity signal
in_u = - y(:,1) - 2*y(:,2); % force signal
FISin = out1; % input to the FIS that we want to train
FISout = in_u; % output to the FIS that we want to train
data1 = [FISin FISout];
% setting up the ANFIS
genOpt = genfisOptions('GridPartition');
genOpt.NumMembershipFunctions = 3;
genOpt.InputMembershipFunctionType = 'gaussmf';
inFIS = genfis(data1(:,1), data1(:,2), genOpt);
opt = anfisOptions('InitialFIS', inFIS, 'EpochNumber', 60);
fis = anfis(data1, opt);
% plotting the results
u = data1(:,1);
anfisOutput = evalfis(fis, u);
plot(u, data1(:,2), '*r', u, anfisOutput,'.b')
grid on, xlabel('y_1'), ylabel('u'),
legend('Training Data', 'ANFIS Output', 'Location', 'best')
function dydt = system(t, y)
u = - y(1) - 2*y(2); % input
dydt = [y(2); % state #1 differential equation
u]; % state #2 differential equation
end
1 Comment
Sam Chak
on 12 Aug 2022
I don't know what exactly you want to train because you just mentioned that there are two inputs and two outputs. Moreover, what is the scientific motivation behind the training activity?
You have designed the LQR to make the system to behave as desired.
Do you think that training something would improve the performance? It would be helpful you can provide a little background.
I strongly advise you to write/provide the mathematical equation for the inputs
and
. You are going need them in your ode45() code to generate the data points for the inputs and outputs.
This is just my example to generate the input u based on the equation that I defined:
[t, y] = ode45(@system, [0 10], [1; 0]);
out1 = y(:,1); % generate output 1
out2 = y(:,2); % generate output 2
in_u = - y(:,1) - 2*y(:,2); % generate input
% System dynamics
function dydt = system(t, y)
u = - y(1) - 2*y(2); % input
dydt = [y(2); % state #1 differential equation
u]; % state #2 differential equation
end
Since you have two inputs, I expect there are two equations.
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

