MATLAB: I want to show the global variables IM and LBP in bae workspace from gui ????

global variablesgui

here this my first push button code,
in which IM is global variable
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

global im im2
[path,user_cance]=imgetfile();
if user_cance
msgbox(sprint('Error'),'Error','Error');
return
end
im=imread(path);
im=im2double(im);
im2=im;
axes(handles.axes1);
imshow(im);
*******************************
And now is my second push button ,where IM and LBP are both global variables
% --- Executes on button press in feature.
function feature_Callback(hObject, eventdata, handles)
% hObject handle to feature (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% close all;
% clc;
global im LBP;
[r c]=size(im);
LBP=zeros(256,1);
offset= 3;
LBPindex= 1;
%binvect = zeros(8,1,'int32');
coord = [1 1;1 2;1 3;2 3;3 3;3 2;3 1;2 1];
for i=1:offset:r-1
for j=1:offset:c-1
win=im(i:i+(offset-1),j:j+(offset-1));
counter=1;
binvect = '';
for k=1:1:offset
for l=1:1:offset
if (k==2 && l==2)
else
tmpOne = '1';
tmpZero = '0';
if win(coord(counter,1),coord(counter,2))<win(2,2)
binvect =strcat(binvect,tmpZero);
else
binvect = strcat(binvect,tmpOne);
end
counter = counter+1
end
end
end
%%inner for ends here
%binary to dec conversion
decimalValue= bin2dec(binvect);
%calculate lbp histogram
LBP(decimalValue + 1)= LBP(decimalValue + 1)+1;
end
end
i just want to show my global variables in main or base workspace

Best Answer

Wasif - if you want to write your variables to the base workspace, then use assignin as
assignin('base','LBP',LBP);
assignin('base','im',im);
where these two lines of code would be added to your second pushbutton callback.
Note that you don't need to use global variables when developing a GUI using GUIDE. Just save the variables to the handles structure in the first callback as
handles.im = im;
handles.im2 = im2;
guidata(hObject,handles);
And then, in the second callback, access these variables as
handles.im
handles.im2
to get to the values that were initialized in the other callback.