I want my fitness function stop reading excel data each time ... (I want reduce computation time)
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Abhiram
el 24 de Abr. de 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 comentarios
Ver también
Categorías
Más información sobre Genetic Algorithm en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!