필터 지우기
필터 지우기

how to share a single variables between different callbacks?

조회 수: 2 (최근 30일)
preeti
preeti 2015년 5월 2일
편집: Stephen23 2015년 5월 5일
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!

답변 (1개)

Stephen23
Stephen23 2015년 5월 2일
  댓글 수: 2
preeti
preeti 2015년 5월 2일
Thank you @Stepen .But stil have doubt.Suppose i have already images in axes 1 and I want to store that image in some variable Images{i} What should I do?
Stephen23
Stephen23 2015년 5월 5일
편집: Stephen23 2015년 5월 5일
You could try getimage:
Images{k} = getimage(axes_handle);
or perhaps getframe and frame2im:
f = getframe;
[im,map] = frame2im(f);

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

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by