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

2 vues (au cours des 30 derniers jours)
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

Réponse acceptée

Jan
Jan le 7 Fév 2023
Modifié(e) : Jan le 7 Fév 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);

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB Compiler dans Help Center et File Exchange

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by