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
最满意答案
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
这正是它的意思:如果
den
为0
,则num
和den
的商为0
; 如果num - den >= 0
,则它比num - den
和den
的商多1; 否则它是0
。
value = value + 1
isn’t a valid statement in ado
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 likereturn
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 withvalue = value + 1
was to mutatevalue
, but there are no mutable variables in Haskell. (There are mutable reference types such asIORef
, 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
andden
is0
ifden
is0
; ifnum - den >= 0
, then it’s 1 more than the quotient ofnum - den
andden
; otherwise it’s0
.
相关问答
更多-
我通过实现这个功能解决了它: 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 ...
-
了解haskell代码(Understanding haskell code)[2022-04-10]
-- 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, _) ... -
解析包含#(c预处理器)的haskell源文件时出错(Error parsing haskell source file containing # (c preprocessor))[2024-01-30]
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 ...
-
在haskell代码中解析错误(error parsing in haskell code)[2023-01-28]
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 ...
-
在Haskell中解析日志文件(Parsing a log file in Haskell)[2022-05-02]
我修改了我的CIS194解决方案(第2周)。 转换为二进制树数据结构和从文件中读取延迟将是学习的好习惯。 type Name = String type Count = Int data MessageType = Param Name Count | Error String | Unknown String deriving (Show, Eq) parseMessage :: Stri ...