首页 \ 问答 \ matlab GUI回调(matlab GUI callback)

matlab GUI回调(matlab GUI callback)

我在m文件中有这个功能,我想对按钮进行回调,但我不知道如何。 谁能帮我? 这是功能:

function f=fftreal(f,N,dim);
error(nargchk(1,3,nargin));

if nargin<3
  dim=[];  
end;

if nargin<2
  N=[];
end;

if ~isreal(f)
  error('Input signal must be real.');
end;


[f,N,Ls,W,dim,permutedsize,order]=assert_sigreshape_pre(f,N,dim,'FFTREAL');

N2=floor(N/2)+1;

f=comp_fftreal(f);

permutedsize(1)=N2;

f=assert_sigreshape_post(f,dim,permutedsize,order);
end

这是GUI自动生成的用户界面代码:

function varargout = Fourier_Transform_GUI(varargin)
%FOURIER_TRANSFORM_GUI M-file for Fourier_Transform_GUI.fig
%      FOURIER_TRANSFORM_GUI, by itself, creates a new FOURIER_TRANSFORM_GUI or raises the existing
%      singleton*.
%
%      H = FOURIER_TRANSFORM_GUI returns the handle to a new FOURIER_TRANSFORM_GUI or the handle to
%      the existing singleton*.
%
%      FOURIER_TRANSFORM_GUI('Property','Value',...) creates a new FOURIER_TRANSFORM_GUI using the
%      given property value pairs. Unrecognized properties are passed via
%      varargin to Fourier_Transform_GUI_OpeningFcn.  This calling syntax produces a
%      warning when there is an existing singleton*.
%
%      FOURIER_TRANSFORM_GUI('CALLBACK') and FOURIER_TRANSFORM_GUI('CALLBACK',hObject,...) call the
%      local function named CALLBACK in FOURIER_TRANSFORM_GUI.M with the given input
%      arguments.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help Fourier_Transform_GUI

% Last Modified by GUIDE v2.5 05-Dec-2012 15:46:34

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @Fourier_Transform_GUI_OpeningFcn, ...
                   'gui_OutputFcn',  @Fourier_Transform_GUI_OutputFcn, ...
                   'gui_LayoutFcn',  [], ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
   gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before Fourier_Transform_GUI is made visible.
function Fourier_Transform_GUI_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   unrecognized PropertyName/PropertyValue pairs from the
%            command line (see VARARGIN)

% Choose default command line output for Fourier_Transform_GUI
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes Fourier_Transform_GUI wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = Fourier_Transform_GUI_OutputFcn(hObject, eventdata, handles)
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes on button press in exit.
function exit_Callback(hObject, eventdata, handles)
% hObject    handle to exit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in FFT.
function FFT_Callback(hObject, eventdata, handles)
% hObject    handle to FFT (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in iFFT.
function iFFT_Callback(hObject, eventdata, handles)
% hObject    handle to iFFT (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in DFT.
function DFT_Callback(hObject, eventdata, handles)
% hObject    handle to DFT (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in iDFT.
function iDFT_Callback(hObject, eventdata, handles)
% hObject    handle to iDFT (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in load_file.
function load_file_Callback(hObject, eventdata, handles)
% hObject    handle to load_file (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

I have this function in an m-file and I want to make a callback for push button but I have no clue how. Can anyone help me? This is the function:

function f=fftreal(f,N,dim);
error(nargchk(1,3,nargin));

if nargin<3
  dim=[];  
end;

if nargin<2
  N=[];
end;

if ~isreal(f)
  error('Input signal must be real.');
end;


[f,N,Ls,W,dim,permutedsize,order]=assert_sigreshape_pre(f,N,dim,'FFTREAL');

N2=floor(N/2)+1;

f=comp_fftreal(f);

permutedsize(1)=N2;

f=assert_sigreshape_post(f,dim,permutedsize,order);
end

This is the user interface code that the GUI automatically generated:

function varargout = Fourier_Transform_GUI(varargin)
%FOURIER_TRANSFORM_GUI M-file for Fourier_Transform_GUI.fig
%      FOURIER_TRANSFORM_GUI, by itself, creates a new FOURIER_TRANSFORM_GUI or raises the existing
%      singleton*.
%
%      H = FOURIER_TRANSFORM_GUI returns the handle to a new FOURIER_TRANSFORM_GUI or the handle to
%      the existing singleton*.
%
%      FOURIER_TRANSFORM_GUI('Property','Value',...) creates a new FOURIER_TRANSFORM_GUI using the
%      given property value pairs. Unrecognized properties are passed via
%      varargin to Fourier_Transform_GUI_OpeningFcn.  This calling syntax produces a
%      warning when there is an existing singleton*.
%
%      FOURIER_TRANSFORM_GUI('CALLBACK') and FOURIER_TRANSFORM_GUI('CALLBACK',hObject,...) call the
%      local function named CALLBACK in FOURIER_TRANSFORM_GUI.M with the given input
%      arguments.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help Fourier_Transform_GUI

% Last Modified by GUIDE v2.5 05-Dec-2012 15:46:34

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @Fourier_Transform_GUI_OpeningFcn, ...
                   'gui_OutputFcn',  @Fourier_Transform_GUI_OutputFcn, ...
                   'gui_LayoutFcn',  [], ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
   gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before Fourier_Transform_GUI is made visible.
function Fourier_Transform_GUI_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   unrecognized PropertyName/PropertyValue pairs from the
%            command line (see VARARGIN)

% Choose default command line output for Fourier_Transform_GUI
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes Fourier_Transform_GUI wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = Fourier_Transform_GUI_OutputFcn(hObject, eventdata, handles)
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes on button press in exit.
function exit_Callback(hObject, eventdata, handles)
% hObject    handle to exit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in FFT.
function FFT_Callback(hObject, eventdata, handles)
% hObject    handle to FFT (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in iFFT.
function iFFT_Callback(hObject, eventdata, handles)
% hObject    handle to iFFT (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in DFT.
function DFT_Callback(hObject, eventdata, handles)
% hObject    handle to DFT (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in iDFT.
function iDFT_Callback(hObject, eventdata, handles)
% hObject    handle to iDFT (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in load_file.
function load_file_Callback(hObject, eventdata, handles)
% hObject    handle to load_file (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

原文:https://stackoverflow.com/questions/13725098
更新时间:2024-01-27 06:01

最满意答案

value = value + 1不是do块中的有效语句。 唯一有效的陈述是:

  • 变量绑定: let pattern = expression

  • monadic binding: pattern <- expression

  • 一个表达式,用于评估monadic动作

但是,您不需要do块,因为您不需要monadic副作用来实现此功能。 此外, return不像命令式语言中的return - 它不是从当前函数返回的关键字,而是创建返回值的操作的函数。 看起来你的value = value + 1意图是改变value ,但Haskell中没有可变变量。 (有一些可变的引用类型,例如IORef ,但你在这里不需要它们。)

因此,一种解决方案是简单地使用表达式:

divideBy :: (Ord a, Num a) => a -> a -> a
divideBy _ 0 = 0
divideBy num den
    | num - den >= 0 = 1 + divideBy (num - den) den
    | otherwise = 0

这正是它的意思:如果den0 ,则numden的商为0 ; 如果num - den >= 0 ,则它比num - denden的商多1; 否则它是0


value = value + 1 isn’t a valid statement in a do block. The only valid statements are:

  • A variable binding: let pattern = expression

  • A monadic binding: pattern <- expression

  • An expression that evaluates to a monadic action

However, you don’t need a do block because you don’t need monadic side effects to implement this function. Furthermore, return isn’t like return in an imperative language—it’s not a keyword that returns from the current function, but a function that creates an action that returns a value. It looks like your intent with value = value + 1 was to mutate value, but there are no mutable variables in Haskell. (There are mutable reference types such as IORef, but you don’t need them here.)

So one solution is to simply use an expression:

divideBy :: (Ord a, Num a) => a -> a -> a
divideBy _ 0 = 0
divideBy num den
    | num - den >= 0 = 1 + divideBy (num - den) den
    | otherwise = 0

This says exactly what it means: the quotient of num and den is 0 if den is 0; if num - den >= 0, then it’s 1 more than the quotient of num - den and den; otherwise it’s 0.

相关问答

更多
  • 我通过实现这个功能解决了它: fatalError :: (Show a1, Show a) => [Char] -> a -> a1 -> t fatalError s l c = error ("Error at line " ++ (show l) ++ " column " ++ (show c) ++ ": " ++ s) 当检测到错误时我从生产中调用它 I've solved it by implementing this function: fatalError :: (Show a1, S ...
  • -- Filter a list... filter -- ...of nested tuples where the first element of the second element of the tuple... (\(_, (variable1, _)) -> -- ...is not an element of [something1, something2] variable1 `notElem` [something1, something2]) (_, (varible1, _) ...
  • Haskell-src-exts本身不支持CPP(在GitHub问题跟踪器中没有问题,但是在trac上的旧问题在http://trac.haskell.org/haskell-src-exts/ticket/27 )。 您可以查看haskell-src-exts解析模块的解决方案或解决方法,使用CPP无法解决问题(使用cpphs)。 还有一个名为hse-cpp的软件包( https://hackage.haskell.org/package/hse-cpp ),看起来它可以为你运行cpphs,但我没有使用过 ...
  • simpleHTTP是多态的。 包含的响应主体可以是严格的ByteString ,lazy ByteString或String任何一个。 它选择其中一个来匹配传递给它的Request ty值。 不幸的是, HTTP是一个旧的库并且维护得很差 - 它最低限度地添加了使用这三种类型所必需的多态性,但并不是它可以使图书馆友好使用的所有地方。 例如,使用getRequest强制响应为String ,从而使simpleHTTP的多态simpleHTTP 。 这是一个使用HTTP抓取该URL内容并使用aeson解码它们 ...
  • 请注意, parseAll使用某种parseAll解析器库(从使用符号和绑定可以看出)。 monad的强大之处在于你选择的parsePayloadA和parsePayloadB可以依赖于hdr :你拥有Haskell的全部功能来检查hdr 。 所以基本上你可以做点什么 parseAll = do hdr <- parseHeader payload <- case somethingInTheHdr hdr of ThisIsAnA -> do a <- pa ...
  • value = value + 1不是do块中的有效语句。 唯一有效的陈述是: 变量绑定: let pattern = expression monadic binding: pattern <- expression 一个表达式,用于评估monadic动作 但是,您不需要do块,因为您不需要monadic副作用来实现此功能。 此外, return不像命令式语言中的return - 它不是从当前函数返回的关键字,而是创建返回值的操作的函数。 看起来你的value = value + 1意图是改变value ...
  • 也许是这样的? value = do skipMany space choice $ map try [ do string "n/a" <|> (eof >> return []) return $ N Nothing, do d <- many digit return $ N $ Just (read d) -- do ... ...
  • 这是因为你在做这么many alphaNum <|> many space 。 many接受0作为可接受的字符数量,它总是成功的。 这与正则表达式中的*行为相同。 所以在一个<|>它永远不会失败并呼叫右侧。 所以你说“尝试尽可能多的alphaNum然后采取一个" 。 你想要的是 many (alphaNum <|> space) 换句话说,“尽可能多的alphaNum s或space s”。 It's because you're doing this many alphaNum <|> many sp ...
  • 我已经使用Parsec创建了您正在寻找的解析器,以便您了解Parsec解析器的外观,因为您声明您对它没什么经验。 即使Haskell经验很少,它也应该具有相当的可读性。 我已经提供了一些关于特别需要注意的部分的评论。 import Text.Read (readMaybe) import Data.Maybe (fromMaybe) import Text.Parsec (parse, many, many1, digit, char, string, (<|>), choice, try) import ...
  • 我修改了我的CIS194解决方案(第2周)。 转换为二进制树数据结构和从文件中读取延迟将是学习的好习惯。 type Name = String type Count = Int data MessageType = Param Name Count | Error String | Unknown String deriving (Show, Eq) parseMessage :: Stri ...

相关文章

更多

最新问答

更多
  • 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
  • 如何打破按钮上的生命周期循环(How to break do-while loop on button)
  • C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
  • 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
  • 如何并排放置两个元件?(How to position two elements side by side?)
  • 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
  • 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
  • Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
  • 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
  • 电脑高中毕业学习去哪里培训
  • 电脑系统专业就业状况如何啊?
  • IEnumerable linq表达式(IEnumerable linq expressions)
  • 如何在Spring测试中连接依赖关系(How to wire dependencies in Spring tests)
  • Solr可以在没有Lucene的情况下运行吗?(Can Solr run without Lucene?)
  • 如何保证Task在当前线程上同步运行?(How to guarantee that a Task runs synchronously on the current thread?)
  • 在保持每列的类的同时向数据框添加行(Adding row to data frame while maintaining the class of each column)
  • 的?(The ? marks in emacs/haskell and ghc mode)
  • 一个线程可以调用SuspendThread传递自己的线程ID吗?(Can a thread call SuspendThread passing its own thread ID?)
  • 延迟socket.io响应,并“警告 - websocket连接无效”(Delayed socket.io response, and “warn - websocket connection invalid”)
  • 悬停时的图像转换(Image transition on hover)
  • IIS 7.5仅显示homecontroller(IIS 7.5 only shows homecontroller)
  • 没有JavaScript的复选框“关闭”值(Checkbox 'off' value without JavaScript)
  • java分布式框架有哪些
  • Python:填写表单并点击按钮确认[关闭](Python: fill out a form and confirm with a button click [closed])
  • PHP将文件链接到根文件目录(PHP Linking Files to Root File Directory)
  • 我如何删除ListView中的项目?(How I can remove a item in my ListView?)
  • 您是否必须为TFS(云)中的每个BUG创建一个TASK以跟踪时间?(Do you have to create a TASK for every BUG in TFS (Cloud) to track time?)
  • typoscript TMENU ATagParams小写(typoscript TMENU ATagParams lowercase)
  • 武陟会计培训类的学校哪个好点?
  • 从链接中删除文本修饰(Remove text decoration from links)