Why do I get an "undeclared identifier" error when using MEX with the option -D in MATLAB 7.7(R2008b)?

조회 수: 1 (최근 30일)
While using the following code :
var1 = var1_GUI; % value set from the GUI script
outputName = sprintf('file%d', var1);
mex -DVAR1=var1 -output outputName file.c
I get the following error messages:
Error ...file.c: <lineNumber> undeclared identifier `var1'

채택된 답변

MathWorks Support Team
MathWorks Support Team 2009년 6월 27일
The MEX function does not evaluate MATLAB variables from the workspace. In order to evaluate workspace variables, replace the following code:
mex -DVAR1=var1 file.c
with:
eval(['mex -DVAR1=' var1 ' file.c])'
This will make sure that the value of var1 is printed into a string and therefore evaluated.

추가 답변 (0개)

카테고리

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

태그

아직 태그를 입력하지 않았습니다.

제품


릴리스

R2008b

Community Treasure Hunt

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

Start Hunting!

Translated by