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.
0 个评论
采纳的回答
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
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
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 Center 和 File Exchange 中查找有关 Dialog Boxes 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!