필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
Lidank Abiel
Lidank Abiel 2013년 2월 8일
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).
Lidank Abiel
Lidank Abiel 2013년 2월 9일
Thx Mr.Image Analyst for your recommended :)

댓글을 달려면 로그인하십시오.

카테고리

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