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

1 view (last 30 days)
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

Accepted Answer

Jan
Jan on 7 Feb 2023
Edited: Jan on 7 Feb 2023
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);

More Answers (0)

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!