I want my fitness function stop reading excel data each time ... (I want reduce computation time)
2 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Abhiram
on 24 Apr 2025
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 Comments
See Also
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!