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

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

Accepted Answer

Stephen23
Stephen23 on 18 Jun 2018
Edited: Stephen23 on 22 Jun 2018
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 Comments
Walter Roberson
Walter Roberson on 26 Jun 2018
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 on 26 Jun 2018
Edited: Stephen23 on 26 Jun 2018
"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.

Sign in to comment.

More Answers (0)

Categories

Find more on Dialog Boxes in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!