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