how to share a single variables between different callbacks?
1 view (last 30 days)
Show older comments
There are two parts-input and output.
Input components-
axes-axes1,axes2(for displaying the two input images)
radio buttons-to select the input image
pushbutton-Put Image(which wil put the given two images on axes 1 and axes2)
Output components-
pushbutton-Show image(which will show output images when the user click radio button of unput image)
axes-axes4 ,axes5(to display output image)
variables used-
C1= to set counter for each time the radiobutton is clicked
images{C1}=array to store image wen radio button of input image is clicked.
Function used-
store_images()-for storing the images whose radio buttons are clicked.
The gui code is here
function varargout = r_b(varargin)
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @r_b_OpeningFcn, ...
'gui_OutputFcn', @r_b_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before r_b is made visible.
function r_b_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
handles.C1 = 1;
% Update handles structure
guidata(hObject, handles);
% --- Outputs from this function are returned to the command line.
function varargout = r_b_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
% --- Executes on button press in radiobutton1.
function radiobutton1_Callback(hObject, eventdata, handles)
handles.C1 = handles.C1 + 1;
filename =uigetfile({'*.jpg'});
store_images(filename,C1)
% --- Executes on button press in radiobutton2.
function radiobutton2_Callback(hObject, eventdata, handles)
handles.C1 = handles.C1 + 1;
filename=getImage(axes(handles.axes2))
store_images(filename,C1)
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
images=get(0,'UserData')
axes(handles.axes4)
imshow(images{1});
axes(handles.axes5)
imshow(images{2});
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
axes(handles.axes1)
imshow('rice.png');
axes(handles.axes2)
imshow('1.jpg');
store_images function code is here-
function [a b]=store_images(filename,C1)
I=imread(filename);
images1 = cell(1,30);
images1{C1} = I;
set(0,'Userdata',images1)
But this code is not working:( Any help will be appreciated!
0 Comments
Answers (1)
See Also
Categories
Find more on Interactive Control and Callbacks in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!