I want my fitness function stop reading excel data each time ... (I want reduce computation time)
2 次查看(过去 30 天)
显示 更早的评论
I use a gamultiobj optimization code to optimize my fitness function and there I have 2 excel file which I use xlsread for impoting the same data each time and that takes time! ... anyone can help me with this ?
0 个评论
回答(1 个)
Abhiram
2025-4-24
Reading Excel files with ‘xlsread’ inside your fitness function every time it is called is very inefficient, especially during optimization where the fitness function is evaluated thousands of times. The best practice is to read the data only once before the optimization starts and then pass it as parameters to your fitness function.
An example implementation of this solution is given:
% Read tables once before optimization
data1 = readtable('first_file.xlsx');
data2 = readtable('second_file.xlsx');
% Pass the pre-loaded data to objective function
fitnessFcn = @(x) objective_function(x, data1, data2);
% Run optimization
[x, fval] = gamultiobj(fitnessFcn, nvars);
Additionally, for newer versions of MATLAB, it is recommended to use ‘readtable’ instead of ‘xlsread’ as ‘readtable’ is generally faster, more robust, and more flexible for reading Excel files.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Genetic Algorithm 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!