how to call a variable in a button function from another button function

1 次查看(过去 30 天)
if true
function Open_Callback(hObject, eventdata, handles)
global citra
try
[filename, foldername] = uigetfile('*.jpg');
if filename ~= 0
FileName = fullfile(foldername, filename);
end
citra = imread(FileName);
imshow((citra), 'Parent', handles.axes3);
catch citra
pesan = 'Input gambar format jpg';
uiwait(warndlg(pesan));
stop;
end
end
if true
function Run_Callback(hObject, eventdata, handles)
% hObject handle to Run (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% global citra
if true
hFH = imfreehand();
gambarmask1 = hFH.createMask();
pesan = questdlg('Lanjutkan Proses?');
if strcmp(pesan,'No')
set(handles.Run,'Enable','off');
end
if strcmp(pesan,'Cancel')
set(handles.Run,'Enable','off');
end
try
if strcmp(pesan,'Yes')
hFH2 = imfreehand();
% Membuat masking dari sebuah area
gambarmask2 = hFH2.createMask();
if strcmp(pesan,'No')
set(handles.Run,'Enable','off');
end
if strcmp(pesan,'Cancel')
set(handles.Run,'Enable','off');
end
pesan = questdlg('Lanjutkan Proses?');
if strcmp(pesan,'Yes')
hFH3 = imfreehand();
gambarmask3 = hFH3.createMask();
if strcmp(pesan,'No')
set(handles.Run,'Enable','off');
end
if strcmp(pesan,'Cancel')
set(handles.Run,'Enable','off');
end
pesan = questdlg('Lanjutkan Proses?');
if strcmp(pesan,'Yes')
hFH4 = imfreehand();
gambarmask4 = hFH4.createMask();
else
end
end
tampung = gambarmask1 + gambarmask2 + gambarmask3 + gambarmask4;
imshow(tampung);
warning = questdlg('Ukur Jaraknya');
if strcmp(warning,'Yes')
global citra
I = imread(citra);
axes(handles.axes3);
imshow(handles.citra);
I want to call variable citra in button open function from button run function

回答(2 个)

Image Analyst
Image Analyst 2013-2-8

Azzi Abdelmalek
Azzi Abdelmalek 2013-2-8
编辑:Azzi Abdelmalek 2013-2-8
If var1 is your variable, when var1 is created or updated:
handles.var1=var1
guidata(hObject,handles)
To call your variable var1 in others functions
var1=handles.var1
  3 个评论
Image Analyst
Image Analyst 2013-2-9
编辑:Image Analyst 2013-2-9
Well if you aren't going to read the FAQ, then simply put
global I;
inside every function that needs to use I. I'm also recommending that you don't use I (upper case i) as a variable name. It looks too much like 1 and l (lower case L).

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by