如何在MATLAB中到达另一个回调函数中加载的变量?

时间:2021-04-26 04:15:05

I want to load a neural network object file with a pushbutton and use it in other pushbutton's callback function.

我想用按钮加载一个神经网络目标文件,并在其他按钮的回调函数中使用它。

I am not using GUIDE, I am creating the GUI programmatically. Here is my code:

我没有使用GUIDE,我正在以编程方式创建GUI。这是我的代码:

function ASR()

figure('Name','Automatic Isolated Speech Rcognition System',.......
   'Menubar','none',........
   'Color',[1 1 1]);

Rcrd_and_Recog =uicontrol('Style','pushbutton',....
                           'Units','normalized',....
                           'Position',[0.75 0.75 0.20 0.05],....
                           'String','START',....
                           'Callback',@Record_Recog);

LD_net = uicontrol('Style','pushbutton',....
                            'Units','normalized',....
                            'Position',[0.75 0.65 0.20 0.05],....
                            'String','LOAD THE NET',....
                            'Callback',@load_net);

function load_net(varargin)
    [file path]=uigetfile('*.mat','Select the M-file');
    if ~isequal(file, 0)
        L=load(fullfile(path,file));
        Net=fieldnames(L);
        net=Net{1};
        handles.net=net;
    end

 function Record_Recog(varargin)
     fs=16000;
     y=wavrecord(1*fs,fs,1,'double');

     if length(y)<1157
         result=sim(net0,cat(1,y,zeros(1157-length(y),1)))
     else
         result=sim(net0,y)
     end
 end

I loaded the net variable but I cannot reach it from Rcrd_and_Recog. How can I reach it?

我加载了net变量,但我无法从Rcrd_and_Recog到达它。我该怎么办?

1 个解决方案

#1


0  

I don't see where net0 is declared. You should use global variables if you want to share them between different functions

我没有看到net0声明在哪里。如果要在不同函数之间共享它们,则应使用全局变量

#1


0  

I don't see where net0 is declared. You should use global variables if you want to share them between different functions

我没有看到net0声明在哪里。如果要在不同函数之间共享它们,则应使用全局变量