【问题标题】:optional output function variable Matlab可选输出函数变量 Matlab
【发布时间】:2014-06-03 13:04:40
【问题描述】:

我有一个 Input 函数,它有两个选项供用户输入,GUI 和来自 Command 在 Matlab 中。 GUI 是通过回调和Command 输入的,变量简单。我想为它构建一个函数,但无法创建为 GUI 不需要任何输出函数变量,而 Command 需要一个变量,在我的情况下如何创建函数?

我的代码:

function varargout = Input()

choice = questdlg(sprintf([ '1. GUI \n\n' '2. Command \n\n' ]), 'Input Choice?', 'GUI', 'Command', 'Command');
switch choice
    case 'GUI'
        GUI();
    case 'Command'

        [p] = Command;
        if nargout > 0
        varargout{1} = p;
        end
end
end

【问题讨论】:

  • 为什么不使用它的自定义输出,例如 varargout{1} = [];或可变参数{1} = 0; GUI(); 的正下方表示选择了 GUI 选项?
  • @Divakar 我不能很好地理解你的观点,请写下答案,以便我了解你的观点。
  • 类似这样的东西 - case 'GUI', GUI();varargout{1} = []; 然后case 'Command' ....
  • @Divakar 当我调用像p=Input 这样的函数时,它只适用于case 'Command'GUI() 给出p 的错误,这就是问题所在。
  • 我试过了,效果很好。

标签: matlab function user-interface output


【解决方案1】:

没错。只需将行 if nargout>0, varargout{1} = []; end 放在 GUI() 之后即可。那应该不是问题。但是,改用varargout{1} = 0; 之类的东西可能会更好。这样您就可以确保函数正确执行。任何其他输出或根本没有输出都意味着该函数没有正确执行。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-06-21
    • 2016-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多