필터 지우기
필터 지우기

Index exceeds the number of array elements. Index must not exceed 1.

조회 수: 3 (최근 30일)
Deepti t
Deepti t 2024년 2월 7일
댓글: Sam Chak 2024년 2월 8일
function cost = optimize_PID(k)
assignin('base', 'k', k);
sim('DABvoltagecontrol.slx');
ITAE = load('ITAE.mat');
num_samples = size(ITAE.ans , 1);
ITAE_value = ITAE.ans(1, num_samples);
cost = ITAE_value(num_samples);
end
while executing the code, error is showing : Index exceeds the number of array elements. Index must not exceed 1. the ITAE is loaded to .mat format

답변 (2개)

Torsten
Torsten 2024년 2월 7일
편집: Torsten 2024년 2월 7일
num_samples = size(ITAE.ans , 1);
ITAE_value = ITAE.ans(1, num_samples);
num_samples is the number of rows of ITAE.ans, but you use it in setting ITAE_value as if it were the number of columns.
Maybe you mean
ITAE_value = ITAE.ans(num_samples,1);
?
  댓글 수: 2
Deepti t
Deepti t 2024년 2월 7일
Still the error shows.
Index exceeds the number of array elements. Index must not
exceed 1.
Error in optimize_PID (line 7)
cost = ITAE_value(num_samples);
Torsten
Torsten 2024년 2월 7일
ITAE_value is a scalar - there is no element number num_samples of ITAE_value because there is only one.

댓글을 달려면 로그인하십시오.


Sam Chak
Sam Chak 2024년 2월 7일
I would recommend calculating the ITAE (Integral of Time-weighted Absolute Error) within the Simulink model and connecting the output to the 'Outport' block. This approach is more straightforward. However, it appears that you are searching for a single parameter, k in the 3-gain PID controller, to minimize the ITAE. Here is a code snippet that may help you with that:
function cost = optimize_PID(k)
assignin('base', 'k', k);
[t, x, y] = sim('DABvoltagecontrol.slx');
cost = y(end, 1); % number 1 Outport block
end
  댓글 수: 10
Deepti t
Deepti t 2024년 2월 8일
이동: Sam Chak 2024년 2월 8일
I am able to get out.ITAE in the array format and also the cost variable showing the out.ITAE values, but the whole function is not working, " unrecognised field: ITAE"
Sam Chak
Sam Chak 2024년 2월 8일
But your error says that out.ITAE is a time series data. Despite setting the To Workspace block to send data as 'Array', it seems that the logged data is still in the 'Time series' format. Am I missing something?
out.ITAE
timeseries
Common Properties:
Name: ''
Time: [328012x1 double]
TimeInfo: [1x1 tsdata.timemetadata]

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Genetic Algorithm에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by