I am currently trying to run a program that shows a progressing series of blocks that are colored to indicate pressure level (this is for a user to see and respond to). The rate of increase is controlled by a timer and colored blocks are loaded images onto axes.
The program actually runs when in debug mode and a break point is placed in the case statement for the function "raisePressure", but when this code is run instead of loading the images into the referenced axes after the first image, the program retrieves a handle to an axis that doesn't exist and simply creates a new window for the output.
Here is the main code of this program, but if necessary I can upload the the rest of the program.
function varargout = PressureMonitor(varargin)% PRESSUREMONITOR MATLAB code for PressureMonitor.fig
% PRESSUREMONITOR, by itself, creates a new PRESSUREMONITOR or raises the existing
% singleton*.
%
% H = PRESSUREMONITOR returns the handle to a new PRESSUREMONITOR or the handle to
% the existing singleton*.
%% PRESSUREMONITOR('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in PRESSUREMONITOR.M with the given input arguments.
%% PRESSUREMONITOR('Property','Value',...) creates a new PRESSUREMONITOR or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before PressureMonitor_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to PressureMonitor_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 PressureMonitor
% Last Modified by GUIDE v2.5 29-Oct-2012 17:23:51
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @PressureMonitor_OpeningFcn, ... 'gui_OutputFcn', @PressureMonitor_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []);if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1});endif nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});else gui_mainfcn(gui_State, varargin{:});end% End initialization code - DO NOT EDIT
end% --- Executes just before PressureMonitor is made visible.
function PressureMonitor_OpeningFcn(hObject, ~, 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 PressureMonitor (see VARARGIN)
handles.white = imread('white.png');handles.red = imread('red.png');handles.green = imread('green.png');handles.pressureLevel = 0;% Choose default command line output for PressureMonitor
handles.output = hObject;% Setup timer object
handles.guifig = gcf;handles.timer = timer('Period', 1.0, 'ExecutionMode', 'FixedRate','TimerFcn', {@increment,handles.guifig});%.guifig
guidata(handles.guifig,handles);% Update handles structure
guidata(hObject, handles);releasePressure(7,handles);% UIWAIT makes PressureMonitor wait for user response (see UIRESUME)
% uiwait(handles.figure1);
end% --- Outputs from this function are returned to the command line.
function varargout = PressureMonitor_OutputFcn(hObject, ~, 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;% Update handles structureguidata(hObject, handles);end% --- Executes on button press in start.
function start_Callback(hObject, ~, handles) % hObject handle to start (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB start(handles.timer); guidata(hObject, handles); end% --- Executes on button press in releasePressure.
function releasePressure_Callback(hObject, ~, handles) % hObject handle to releasePressure (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) prevLevel = handles.pressureLevel; handles.pressureLevel = releasePressure(handles.pressureLevel,handles); if(handles.pressureLevel == 0 && prevLevel > 6) tElapsed = toc(handles.tStart); disp(tElapsed) end % Update handles
guidata(hObject, handles);endfunction nLevel = releasePressure(level,handles) if(level > 6) set(handles.guifig,'CurrentAxes',handles.axes1); imshow(handles.white); set(handles.guifig,'CurrentAxes',handles.axes2); imshow(handles.white); set(handles.guifig,'CurrentAxes',handles.axes3); imshow(handles.white); set(handles.guifig,'CurrentAxes',handles.axes4); imshow(handles.white); set(handles.guifig,'CurrentAxes',handles.axes5); imshow(handles.white); set(handles.guifig,'CurrentAxes',handles.axes6); imshow(handles.white); set(handles.guifig,'CurrentAxes',handles.axes7); imshow(handles.white); set(handles.guifig,'CurrentAxes',handles.axes8); imshow(handles.white); nLevel = 0; else nLevel = level; endendfunction nLevel = raisePressure(level,handles) switch level case 0 axes(handles.axes1); imshow(handles.green); nLevel = level + 1; case 1 axes(handles.axes2); imshow(handles.green); nLevel = level + 1; case 2 axes(handles.axes3); imshow(handles.green); nLevel = level + 1; case 3 axes(handles.axes4); imshow(handles.green); nLevel = level + 1; case 4 axes(handles.axes5); imshow(handles.green); nLevel = level + 1; case 5 axes(handles.axes6); imshow(handles.green); nLevel = level + 1; case 6 axes(handles.axes7); imshow(handles.red); nLevel = level + 1; case 7 set(handles.guifig,'CurrentAxes',handles.axes1); imshow(handles.red); set(handles.guifig,'CurrentAxes',handles.axes2); imshow(handles.red); set(handles.guifig,'CurrentAxes',handles.axes3); imshow(handles.red); set(handles.guifig,'CurrentAxes',handles.axes4); imshow(handles.red); set(handles.guifig,'CurrentAxes',handles.axes5); imshow(handles.red); set(handles.guifig,'CurrentAxes',handles.axes6); imshow(handles.red); set(handles.guifig,'CurrentAxes',handles.axes7); imshow(handles.red); set(handles.guifig,'CurrentAxes',handles.axes8); imshow(handles.red); nLevel = level + 1; otherwise nLevel = level; end gca endfunction increment(~,~,handles)% handles structure with handles and user data (see GUIDATA) handle = guidata(handles); handle.pressureLevel = raisePressure(handle.pressureLevel,handle); if(handle.pressureLevel == 7) tic; handle.tStart = tic; end guidata(handles, handle); end% --- Executes on button press in stop.
function stop_Callback(hObject, ~, handles)% hObject handle to stop (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA) stop(handles.timer); guidata(hObject, handles); end
Best Answer