![](/img/trans.png)
[英]How to pass serial communication object from one callback to another callback in matlab
[英]Matlab pass variable from one callback to another
我是Matlab的新手,我想將一個變量傳遞給另一個變量:
這是回調1,其中我用input編寫了變量:
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);
一半guidata(hObject, handles);
。 您可以使用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
現在,您可以從pushbutton1_Callback
訪問handles.b
:
function pushbutton1_Callback(hObject, eventdata, handles)
c = handles.b;
% [...] your code
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.