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
댓글 수: 0
답변 (2개)
Image Analyst
2013년 2월 8일
A variety of ways are covered in the FAQ: http://matlab.wikia.com/wiki/FAQ#How_can_I_share_data_between_callback_functions_in_my_GUI.28s.29.3F
댓글 수: 0
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
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).
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!