Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab将变量从一个回调传递到另一个回调_Matlab_Matlab Guide - Fatal编程技术网

Matlab将变量从一个回调传递到另一个回调

Matlab将变量从一个回调传递到另一个回调,matlab,matlab-guide,Matlab,Matlab Guide,我是matlab新手,我想将一个变量传递给另一个变量: 下面是回调1,我在其中使用输入写入变量: function pushbutton2_Callback(hObject, eventdata, handles) c = {'Enter image size:'}; title = 'Input'; dims = [1 35]; definput = {'500'}; answer = inputdlg(c,title,dims,definput); disp(answer); b = st

我是matlab新手,我想将一个变量传递给另一个变量:

下面是回调1,我在其中使用输入写入变量:

function pushbutton2_Callback(hObject, eventdata, handles)

c = {'Enter image size:'};
title = 'Input';
dims = [1 35];
definput = {'500'};
answer = inputdlg(c,title,dims,definput);
disp(answer);
b = str2double(answer); // I want to pass this b to other callback
disp(b); 
guidata(hObject, handles);
这里我得到了另一个回调,我希望变量b就是我的c

function pushbutton1_Callback(hObject, eventdata, handles)

 h = randi([0 70],c,c); //here I want that c would be my b from another callback
    dlmwrite('myFile.txt',h,'delimiter','\t');


    [file,path] = uigetfile('*.txt');
    fileID = fopen([path,file],'r');
    formatSpec = '%d %f';
    sizeA = [c c];
    A = fscanf(fileID,formatSpec,sizeA);
    fclose(fileID);

    disp(A);
    image(A);
    saveas(gcf,'kazkas.png')
    %uiputfile({'*.jpg*';'*.png'},'File Selection');
guidata(hObject, handles);

您的
guidata(hObject,handles)已经完成了一半。您可以使用
句柄
结构来存储数据,如下所示:

function pushbutton2_Callback(hObject, eventdata, handles)

    % [...] your code
    handles.b = b;              % Store b as a new field in handles
    guidata(hObject, handles);  % Save handles structure
现在,您可以从
按钮1\u回调访问
句柄.b

function pushbutton1_Callback(hObject, eventdata, handles)     
    c = handles.b;
    % [...] your code

关于和的更多信息。

我觉得阅读这篇文章很不公平,而且对Mathworks有些不直观。感谢您的帮助,也许您会发现使用
setappdata()
更具可读性,它可以