English 中文(简体)
Matlab 从函数中调取函数
原标题:Matlab call a function from a function

我有两个功能:

function [] = func_one()
     S.pb = uicontrol( style , push , unit , pix , posit ,[20 20 260 30],
                       string , Print Choices , callback ,{@func_two,S});

我有第二种功能:

   function [a] = func_two(varargin)
       a =  alon ;
   end

我希望 func_one 返回 a 的变量 a 。 请让我怎么做?

我试过了:

 function [a] = func_one()

但我猜我必须做一些 与回调,"func_2,S})

谢谢大家!

最佳回答

如果您想要 func_one 返回 a func_ 2 中的值,那么不使用回调的最简单方法是:

function [a] = func_one()
     S.pb = uicontrol( style , push , unit , pix , posit ,[20 20 260 30],
                       string , Print Choices );

     a = func_two()

上面将允许您说运行 a=func_one a 将是字符串 alon

如果您真的想要 func_ two () 成为您的按键的回调, 您想要将 a= alon 指定在 func_ one 的工作空间( 调用 func_ two 的函数) 中, 然后把它放在 func_ two

assignin( caller , a ,a)

如果两者都不是你想要的,那么也许你可以指出为什么你想要 func_one 返回什么 func_2 返回什么 - 就像你希望与您的 GUI 进行的确切互动, 以及它与您实际经历的情况有何不同 。

问题回答

如果您正在用程序设计一个 GUI, 我建议您使用嵌套函数到 < a href=" http://www. mathworks.com/help/techdoc/matlab_prog/f0-38068.html# f0-50984" rel=“ nofollow noreferrer” >share data 。 例如 :

function IncrementExample()
    x = 0;
    uicontrol( Style , pushbutton ,  String , (0) , ...
         Callback ,@callback);

    function callback(o,e)
        %# you can access the variable x in here
        x = x + 1;

        %# update button text
        set(o,  String ,sprintf( (%d) ,x))
        drawnow
    end
end

""https://i.sstatic.net/1gIkJ.png" alt="此处输入图像描述"/ >





相关问题
Why I can t pass two chars as function arguments in C?

I have a function: int get_symbol(tab *tp, FILE *fp, char delim) and I call it like this: get_symbol(tp, fp, ; ) I always have it declared in the header as: int get_symbol(tab *, FILE *, char); ...

problem w/ linking static function g++

I am trying to build a small program and I have my own library libfoo. I have a camera class that is calling a static function from my Vector3 class (i.e. crossProduct). My camera class and Vector3 ...

taking java method names as function arg in clojure

All, I want to create a function that takes a symbol representing a java method and applies it to some object: (user=> (defn f [m] (. "foo" (m))) When I execute this, I get a result much ...

Def, Void, Function?

Recently, I ve been learning different programming langages, and come across many different names to initalize a function construct. For instance, ruby and python use the def keyword, and php and ...