Is it possible to automatically pass a predefined value to a variable assigned to questdlg, inputdlg, uigetdir (without the input window pop up)?

조회 수: 3 (최근 30일)
I am coding a plugin to be used together with a previously existing code (function). The existing code CAN'T be modified. It contains 3 input variables, taking inputs from uigetdir, inputdlg, questdlg. But now the values for these variables are assigned in the plugin code. Hence I need to somehow skip taking those inputs in the previously existing code without making any changes to it.
1. Is there a way to skip executing certain commands? For example, for the code: " a = inputdlg('Input','Title')", if some value is assigned to ' a' previously, this line of code will not execute, and pass on to the next lines of code.
2. Or, is there a way to automatically pass a default (predefined) value when inputdlg / uigetdir / questdlg pertaining to certain variable name is executed. For example for the line of code: " a = inputdlg('Input','Title')", the usual pop up for inputdlg will not happen, rather automatically the value of ' a' will be retained/passed from the previously assigned value.

채택된 답변

Stephen23
Stephen23 2018년 6월 18일
편집: Stephen23 2018년 6월 22일
Ugh, this is an unfortunate situation to find oneself in... my commiserations. One possible solution is to shadow those functions: simply use a persistent variable to store the default value, which will be returned when the function is called again. (obviously this is a hack solution, and I advise you to rewrite the original code)
function out = inputdlg(inp,varargin)
persistent val
if nargin==1
val = inp;
end
out = val;
end
and then call it like this to store the default:
inputdlg(DefaultValue)
... original code here
and then when it is called inside the existing code it will return the default value.
  댓글 수: 10
Walter Roberson
Walter Roberson 2018년 6월 26일
Create a containers.Map that you populate with variable names and associated value. In your rogue version of inputdlg(), use isKey to check whether the first input is in the container, and if it is then return the associated content; otherwise execute replacement prompting code. (Trying to execute the original Mathworks version when your own has the same name is likely to be a ... challenge.)
Stephen23
Stephen23 2018년 6월 26일
편집: Stephen23 2018년 6월 26일
"Is this achievable? How?"
Inside your function check the input value. Decide what to do based on the value. You will find it difficult to call the original function: you might be able to create a handle to it before shadowing it.
Note that this is an awful hack code and you should rewrite the original code properly.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Dialog Boxes에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by