use function with user defined variable in GA

6 views (last 30 days)
HI every one
I have a fuction which do some calculation on a very big matrix (42588x17)
this matrix came from an excel file which was imported by readmatrix
the fuction itself take less than 2 secound to run like this
FileContent=readmatrix("Export.xlsx")
function z=myfun(x,FileContent)
.
.
.
end
but if i include the readmatrix command inside it, it take upto 50 secound
function z=myfun(x)
FileContent=readmatrix("Export.xlsx")
.
.
end
now i want to run GA on this fuction for variable x but how can i do it without running readmatrix on each run
i tried global variable but it dosent work for me

Accepted Answer

Star Strider
Star Strider on 6 Sep 2021
I have no idea what the fitness funciton does, however if it uses data from the Excel file, read the file once and then pass the necessary variables to the fitness function as extra parameters. See the documentation on Passing Extra Parameters for details.
It is not considered good programming practice to use global variables in any event.
.

More Answers (0)

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!