Effacer les filtres
Effacer les filtres

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

1 vue (au cours des 30 derniers jours)
Lidank Abiel
Lidank Abiel le 8 Fév 2013
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

Réponses (2)

Image Analyst
Image Analyst le 8 Fév 2013

Azzi Abdelmalek
Azzi Abdelmalek le 8 Fév 2013
Modifié(e) : Azzi Abdelmalek le 8 Fév 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 commentaires
Image Analyst
Image Analyst le 9 Fév 2013
Modifié(e) : Image Analyst le 9 Fév 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).
Lidank Abiel
Lidank Abiel le 9 Fév 2013
Thx Mr.Image Analyst for your recommended :)

Connectez-vous pour commenter.

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by