필터 지우기
필터 지우기

Code runs well on Windows but gets errors on Apple Silicon Mac

조회 수: 7 (최근 30일)
Batug
Batug 2024년 5월 13일
댓글: Batug 2024년 5월 14일
paths;
algorithms = {'RSA'};
dimension = 20; % (2, 10, 20)
maxFE = 1000; % 1000000
cec2022 = str2func('cec22_test_func');
globalMins = {300, 400, 600, 800, 900, 1800, 2000, 2200, 2300, 2400, 2600, 2700};
experimentNumber = 1; run = 21;
filename = 'result-';
functionsNumber = 12;
global count;
solution = zeros(experimentNumber, functionsNumber, run);
solutionR = zeros(functionsNumber * experimentNumber, run);
for ii = 1 : length(algorithms)
disp(algorithms(ii));
algorithm = str2func(char(algorithms(ii)));
for i = 1 : functionsNumber
disp(i);
for j = 1 : run
[~, bestFitness, ~] = algorithm(cec2022, dimension, maxFE, i);
disp(count);
count = 0;
solution(1, i, j) = bestFitness - globalMins{i};
for k = 1 : experimentNumber
solutionR(k + experimentNumber * (i - 1), j) = solution(k, i, j);
end
end
end
xlswrite(strcat(filename, func2str(algorithm), '-d=', num2str(dimension), '.xlsx'), solutionR, 1);
eD = strcat(func2str(algorithm), '-Bitti :)');
disp(eD);
end
I've tried this code with my friends Winodws Laptop. We both have just dowloaded Matlab so there is no configuration file for both sides. Error is:
Unrecognized function or variable 'cec22_test_func'.
Error in testFunction (line 29)
fitness = feval(fhd, x, fNumber);
Error in RSA (line 25)
Ffun(1,i)=testFunction(X(i,:)', fhd, fNumber);
Error in main (line 21)
[~, bestFitness, ~] = algorithm(cec2022, dimension, maxFE, i);
My friend runs this codes with no issue. I literally have no idea what's happening...
  댓글 수: 1
Batug
Batug 2024년 5월 13일
이동: Steven Lord 2024년 5월 13일
I've just tried this code on Matlab Online too. It's the similar error. Somehow, the code just works on Windows. Not on Apple Silicon or Matlab Online...

댓글을 달려면 로그인하십시오.

채택된 답변

Batug
Batug 2024년 5월 14일
This might seem very easy but I'm not going to delete this question to help others.
Our instructor gave us this repository and it had "cec22_test_func.cpp" and "cec22_test_func.mexw64" in it. I haven't think through it really much but some time later it crossed my mind. It was compiled on Windows as ".mexw64" file so macOS couldn't see it.
mex cec22_test_func
I've compiled it like this, on my macOS and it's working now!

추가 답변 (1개)

Steven Lord
Steven Lord 2024년 5월 13일
which cec22_test_func
'cec22_test_func' not found.
There is no such function in MATLAB. This is confirmed by a search of the MathWorks website, which only finds this Answers thread.
What you've written likely works on your friend's machine because they've created that function or downloaded it from somewhere.
A quick Google search found a GitHub repo with a function by that name, but that function is implemented as a MEX-file (which is platform dependent) and the repo only has versions of the MEX-file for Microsoft Windows (the .mexw64 extension.) You could try compiling the MEX-file yourself on your Mac machine.
  댓글 수: 2
Batug
Batug 2024년 5월 14일
I forgot to mension that. I already have that in my directory. We both cloned the same repository that our instructors gave.
Batug
Batug 2024년 5월 14일
I've solved the issue and closed the question. Thanks for your help!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품


릴리스

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by