Urgent, help please (probably very easy solution but i couldn't get)

1 view (last 30 days)
I have 2 gui files, one is the main, and the other is running in the opening function of the main gui as a question popup in order to take an input for the usage in the main function. After this, it closes. And when i push the stop button in my main Gui file, getappdata command in this push button callback function does not work, as you can see the "current" value gives nothing to the screen of Matlab. For testing, i type getappdata(0,'current') in the Matlab command window, i can see, but when i press the push button, i cannot see, whatever the problem is, i couldn't get, can anyone help me please?
function stopbutton_Callback(hObject, eventdata, handles)
% hObject handle to stopbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%t=toc;
current = getappdata(0, 'current') ;
current
global timerx;
timery = timerx;
stop(timery)
t = 0;
formttt='%d%d:%0.2f';
t=datevec(t/86400);
s=strrep(sprintf(formttt,t),': ',':0');
global zamanx;
  1 Comment
Walter Roberson
Walter Roberson on 27 Feb 2012
http://www.mathworks.com/matlabcentral/answers/29922-why-your-question-is-not-urgent-or-an-emergency

Sign in to comment.

Answers (4)

Walter Roberson
Walter Roberson on 11 Feb 2012
What does
getappdata(0)
report at that point?
Are you sure you do not have an rmappdata() somewhere?
  2 Comments
Walter Roberson
Walter Roberson on 11 Feb 2012
I am not saying that you _do_ have it, or that you _should_ have it: I am asking you to check whether you have it, as it would be one mechanism by which the appdata could disappear.
Please check getappdata(0) at the end of the opening function, and then after the opening function but before pressing the stop button, and then again within the stop callback.

Sign in to comment.


Image Analyst
Image Analyst on 11 Feb 2012
Obviously there's a lot of code omitted - for example your stop code has a lot of useless stuff that it's probably only partially listed. But I'm wondering why you think "current" should have anything at all in it. Was there code in your OpenFcn() file that loaded something into "current"? That's what Walter was hinting at. Run the code he gave and you'll probably not see current listed, meaning that you never called setappdata() to load anything into it in the first place. Unless you omitted that code, I see no reason why current should be anything other than null.
  5 Comments
Image Analyst
Image Analyst on 11 Feb 2012
I thought 1 was the handle of MATLAB, like fprintf(1, '%s'..... and that 0 was the handle of the active GUI. No? You're probably right. I tried to find in the help where predefined handles numbers (like 0 and 1) are discussed but couldn't find it. Say where if you know where. I always refer to my GUIs by their handle variable rather than some predefined number.
Walter Roberson
Walter Roberson on 27 Feb 2012
0 is the handle of the "root" of the graphics system. No other handle numbers are pre-defined for graphics. The handle of the active GUI is returned by gcf(), with gca() and gcbo() being important calls related to the object system.
When it comes to I/O, file identifiers (not handles) 0, 1, and 2 are pre-defined. 0 is defined for standard input, 1 for standard output, and 2 for standard error. In practice standard error and standard output go to the same place but standard error (2) is unbuffered whereas standard output (1) is buffered.

Sign in to comment.


kaan yilmaz
kaan yilmaz on 11 Feb 2012
the code of the gui of the pop-up(which is in the openingfcn of the main gui) is
function varargout = untitled(varargin)
% UNTITLED MATLAB code for untitled.fig
% UNTITLED by itself, creates a new UNTITLED or raises the
% existing singleton*.
%
% H = UNTITLED returns the handle to a new UNTITLED or the handle to
% the existing singleton*.
%
% UNTITLED('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in UNTITLED.M with the given input arguments.
%
% UNTITLED('Property','Value',...) creates a new UNTITLED or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before untitled_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to untitled_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help untitled
% Last Modified by GUIDE v2.5 10-Feb-2012 23:48:56
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @untitled_OpeningFcn, ...
'gui_OutputFcn', @untitled_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 untitled is made visible.
function untitled_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to untitled (see VARARGIN)
% Choose default command line output for untitled
handles.output = 'Yes';
% Update handles structure
guidata(hObject, handles);
% Insert custom Title and Text if specified by the user
% Hint: when choosing keywords, be sure they are not easily confused
% with existing figure properties. See the output of set(figure) for
% a list of figure properties.
if(nargin > 3)
for index = 1:2:(nargin-3),
if nargin-3==index, break, end
switch lower(varargin{index})
case 'title'
set(hObject, 'Name', varargin{index+1});
case 'string'
set(handles.text1, 'String', varargin{index+1});
end
end
end
% Determine the position of the dialog - centered on the callback figure
% if available, else, centered on the screen
FigPos=get(0,'DefaultFigurePosition');
OldUnits = get(hObject, 'Units');
set(hObject, 'Units', 'pixels');
OldPos = get(hObject,'Position');
FigWidth = OldPos(3);
FigHeight = OldPos(4);
if isempty(gcbf)
ScreenUnits=get(0,'Units');
set(0,'Units','pixels');
ScreenSize=get(0,'ScreenSize');
set(0,'Units',ScreenUnits);
FigPos(1)=1/2*(ScreenSize(3)-FigWidth);
FigPos(2)=2/3*(ScreenSize(4)-FigHeight);
else
GCBFOldUnits = get(gcbf,'Units');
set(gcbf,'Units','pixels');
GCBFPos = get(gcbf,'Position');
set(gcbf,'Units',GCBFOldUnits);
FigPos(1:2) = [(GCBFPos(1) + GCBFPos(3) / 2) - FigWidth / 2, ...
(GCBFPos(2) + GCBFPos(4) / 2) - FigHeight / 2];
end
FigPos(3:4)=[FigWidth FigHeight];
set(hObject, 'Position', FigPos);
set(hObject, 'Units', OldUnits);
% Show a question icon from dialogicons.mat - variables questIconData
% and questIconMap
load dialogicons.mat
IconData=questIconData;
questIconMap(256,:) = get(handles.figure1, 'Color');
IconCMap=questIconMap;
Img=image(IconData, 'Parent', handles.axes1);
set(handles.figure1, 'Colormap', IconCMap);
set(handles.axes1, ...
'Visible', 'off', ...
'YDir' , 'reverse' , ...
'XLim' , get(Img,'XData'), ...
'YLim' , get(Img,'YData') ...
);
% Make the GUI modal
set(handles.figure1,'WindowStyle','modal')
% UIWAIT makes untitled wait for user response (see UIRESUME)
uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = untitled_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% The figure can be deleted now
delete(handles.figure1);
% --- 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)
handles.output = getappdata(0,'current');
% Update handles structure
guidata(hObject, handles);
current = str2double(get(handles.edit1,'string'));
setappdata(0, 'current', current);
if isnan(current)
set(hObject, 'String', 0);
errordlg('Input must be a number','Error');
end
% Use UIRESUME instead of delete because the OutputFcn needs
% to get the updated handles structure.
uiresume(handles.figure1);
% --- Executes when user attempts to close figure1.
function figure1_CloseRequestFcn(hObject, eventdata, handles)
% hObject handle to figure1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if isequal(get(hObject, 'waitstatus'), 'waiting')
% The GUI is still in UIWAIT, us UIRESUME
uiresume(hObject);
else
% The GUI is no longer waiting, just close it
delete(hObject);
end
% --- Executes on key press over figure1 with no controls selected.
function figure1_KeyPressFcn(hObject, eventdata, handles)
% hObject handle to figure1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Check for "enter" or "escape"
if isequal(get(hObject,'CurrentKey'),'escape')
% User said no by hitting escape
handles.output = 'No';
% Update handles structure
guidata(hObject, handles);
uiresume(handles.figure1);
end
if isequal(get(hObject,'CurrentKey'),'return')
uiresume(handles.figure1);
end
function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a double
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
it should work, but it doesn't in the main gui where i called it in the stop button callback as
function stopbutton_Callback(hObject, eventdata, handles)
% hObject handle to stopbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%t=toc;
a = getappdata(0, 'current')
a
global timerx;
timery = timerx;
stop(timery)
t = 0;
formttt='%d%d:%0.2f';
t=datevec(t/86400);
s=strrep(sprintf(formttt,t),': ',':0');
global zamanx;
  3 Comments
kaan yilmaz
kaan yilmaz on 11 Feb 2012
"there is no other reference in the code" --> how can i reference it?
meanwhile, i deleted this line --> "handles.output=getappdata(0,'current');"
I didn't consider update the current as part of edit1_callback, does it change anything?
meanwhile, if i write getappdata(0,'current) in the opening function of main gui, it works, but in the stopbuttoncallback it doesnt, this is the main problem
kaan yilmaz
kaan yilmaz on 11 Feb 2012
and it also works after i close my main gui, when i type "getappdata(0,'current')" in the main matlab command window...
i couldn't understand the problem is stop button

Sign in to comment.


kaan yilmaz
kaan yilmaz on 11 Feb 2012
This codes of both of the Guis work when i type "getappdata(0,'current')" in the main matlab command window after i close the gui. But in the stop button callback, i cannot output "x=getappdata(0,'current')" what is the problem? thanks for the helps

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!