use function with user defined variable in GA

조회 수: 6 (최근 30일)
Mohammad Kalantar
Mohammad Kalantar 2021년 9월 6일
답변: Star Strider 2021년 9월 6일
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

채택된 답변

Star Strider
Star Strider 2021년 9월 6일
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개)

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by