use function with user defined variable in GA
6 views (last 30 days)
Show older comments
Mohammad Kalantar
on 6 Sep 2021
Answered: Star Strider
on 6 Sep 2021
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
0 Comments
Accepted Answer
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.
.
0 Comments
More Answers (0)
See Also
Categories
Find more on Spreadsheets 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!