Clear Filters
Clear Filters

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

1 view (last 30 days)
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

Answers (2)

Image Analyst
Image Analyst on 8 Feb 2013

Azzi Abdelmalek
Azzi Abdelmalek on 8 Feb 2013
Edited: Azzi Abdelmalek on 8 Feb 2013
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 Comments
Image Analyst
Image Analyst on 9 Feb 2013
Edited: Image Analyst on 9 Feb 2013
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).

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!