Error in optimization with GA: Struct contents reference from a non-struct array object
Show older comments
Hi, I'm new to Matlab and Simulink. I am going to optimize my Simulink model using the genetic algorithm.
The optimization can run, but it does not work at the plot of the results for each GA-generations. When the optimization ends, I can not obtain the best result with the optimal variables. The only thing is an error:
Error running optimization. Struct contents reference from a non-struct array object.
Here is my function:
function grades = rules(Vars)
........
........
% Data from Simulink model
[y] =sim('Model',1000);
% Data are imported from Data file
load('uH.mat');
x_d = y(1:8001,1);
x_ud = uH(1:8001,2);
RMS_1 = sqrt(sum(x_d.*x_d)/8001);
RMS_2 = sqrt(sum(x_ud.*x_ud)/8001);
% fitness function
grade_RMS_x = (RMS_x_ud - RMS_x_d) / RMS_x_ud;
grades = 1 - grade_RMS_x;
end
It would be perfect if someone could help me out. :) Thank you so so much!
2 Comments
Walter Roberson
on 6 Sep 2017
Is uH.mat being written by the model using a ToFile block? Then if so note that the default is to write as a Timeseries object https://www.mathworks.com/help/simulink/slref/tofile.html and that even if you specify Array that the first column will be timestamps.
Junyu Chen
on 7 Sep 2017
Answers (0)
Categories
Find more on Genetic Algorithm 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!