필터 지우기
필터 지우기

Compiled code to use str2func to call an application (mlapp file) fails while the same code works in the MATLAB environment

조회 수: 1 (최근 30일)
I use str2func to allow the same code to call different graphics applications. Code snippet below
graphicsApp= str2func([g, 'Plot']);
% app.hTemp = graphicsApp(app, app.tsurf, app.p,...
% app.nPlots.(g), app.userFilePath);
app.hTemp = HBCPlot(app, app.tsurf, app.p,...
app.nPlots.(g), app.userFilePath);
Both versions of code work in the MATLAB environment as expected, but the commented code never opens the graphics application, "HBCPlot", in the particular instance where g='HBC'. It's easy enough to work around this particular block of code, but I subsequently use the graphics handles elsewhere so I've got to get this to work. I've examined the handle of course, @HBCPlot, and given the code works in the native environment I'm at a loss.
I wrote a simple test case, code below:
Teststr2fcn(1);
name=['Test','str2fcn'];
hTeststr2fcn= str2func(name);
hTeststr2fcn(2);
When this code is compiled both instances of Teststr2fcn appear

채택된 답변

Jan
Jan 2023년 2월 7일
편집: Jan 2023년 2월 7일
A bold guess: Is HBCPlot() included in the compiled application? If its name is hidden, Matlab cannot guess, that it has to be included. I'm not sure if "I've examined the handle of course, @HBCPlot" means exactly this problem.
Maybe this is a cleaner solution:
switch g
case 'HBC'
PlotFcn = @HBCPlot;
otherwise
error('Unknown plot function');
end
app.hTemp = plotFcn(app, app.tsurf, app.p,...
app.nPlots.(g), app.userFilePath);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by