필터 지우기
필터 지우기

How to fake an app handle in the arguments?

조회 수: 1 (최근 30일)
Adrian
Adrian 2022년 10월 5일
댓글: Adrian 2022년 10월 6일
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에서 Argument Definitions에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by