How to fake an app handle in the arguments?

5 次查看(过去 30 天)
Hello.
I am working on a project which involves an app. What I do is to give the submethods a handle to the app, so that they can use the apps getter and setter methods, as well as the log file. This is done via Argument Validation, aka:
function [] = myFun(I, app, opt)
arguments
I (:, :) uint8 % the image
app (1, 1) eva
% Handle back to the app, to transfer data
opt.whatever1 (1, 1) {mustBeNumeric} = 100
opt.whatever2 (1, 1) {mustBeNumeric} = 100
opt.debug (1, 1) logical = false
end
% Function code
end
Now what I would like to do, is to be able to call the function like myFun(I, ?, 'debug', true), where I use the debug flag to not go into the parts of the code which actually uses the app handle. This would allow me to call the methods in the command line and not just from inside the app. In this case the '?' stands for whatever can be used. Empty strings or arrays do not work. Naively I'd use something like a Nullpointer, but I don't know if something like that exists in Matlab.
Any ideas or insights would be chuffing tremendous. Or if you know that this won't work as intended, that'd be good to know as well.

采纳的回答

dpb
dpb 2022-10-5
Use mustBeScalarOrEmpty validation function instead of fixed size would get past that hurdle. I've no klew whether it'll actually work as intended or not, I've never used any of the argument validation stuff...
  1 个评论
Adrian
Adrian 2022-10-6
This seems to work.
Additionally I can set
opt.debug (1, 1) logical = isempty(app);
which immediately sets the debug flag as intended.
Thank you very much.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by