1
votes

i tried create a matlab gui using a axes and a turn on button using an example i got from mathwork. However it give me these errors which i cannot fix. Can anyone tell me what happen?

Reference to non-existent field 'txtInfo'.

Error in realtime21>btnPreviewVideo_Callback (line 100) set(handles.txtInfo, 'string', errorMessage);

Error in gui_mainfcn (line 96) feval(varargin{:});

Error in realtime21 (line 42) gui_mainfcn(gui_State, varargin{:});

Error in @(hObject,eventdata)realtime21('btnPreviewVideo_Callback',hObject,eventdata,guidata(hObject))

Error while evaluating uicontrol Callback

the code

function varargout = realtime21(varargin)
% REALTIME21 MATLAB code for realtime21.fig
%      REALTIME21, by itself, creates a new REALTIME21 or raises the existing
%      singleton*.
%
%      H = REALTIME21 returns the handle to a new REALTIME21 or the handle to
%      the existing singleton*.
%
%      REALTIME21('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in REALTIME21.M with the given input arguments.
%
%      REALTIME21('Property','Value',...) creates a new REALTIME21 or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before realtime21_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to realtime21_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 realtime21

% Last Modified by GUIDE v2.5 28-Apr-2015 11:02:05

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
               'gui_Singleton',  gui_Singleton, ...
               'gui_OpeningFcn', @realtime21_OpeningFcn, ...
               'gui_OutputFcn',  @realtime21_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 realtime21 is made visible.
function realtime21_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 realtime21 (see VARARGIN)

% Choose default command line output for realtime21
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes realtime21 wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = realtime21_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;


% --- Executes on button press in btnPreviewVideo.
function btnPreviewVideo_Callback(hObject, eventdata, handles)
% hObject    handle to btnPreviewVideo (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
    % Initialize the video camera.
global vidobj;  % Video camera object.
try
    % Initialize Logitech webcam
    vidobj = videoinput('winvideo', 1, 'YUY2_320x240');
    if ~isempty(vidobj)
        src = getselectedsource(vidobj);
        vidobj.FramesPerTrigger = 1;
        axes(handles.axesImage);
        hImage = findobj(handles.axesImage, 'Type', 'image');
        preview(vidobj, hImage);
%           src.ZoomMode = 'manual';
        % Turn on the live video preview.  Display the bounding box over it if there is one selected.
        TurnOnLiveVideo(handles);
    end
    % Turn on the live video preview.  Display the bounding box over it if there is one selected.
    TurnOnLiveVideo(handles);
catch ME
        errorMessage = sprintf('Error in function       logitech_webcam_OpeningFcn.\nNo Logitech webcam detected!\n\nError      Message:\n%s', ME.message);
    set(handles.txtInfo, 'string', errorMessage);
    uiwait(warndlg(errorMessage));
end

%=====================================================================
% Turn on the live video preview.  Display the bounding box over it if there is one selected.
function TurnOnLiveVideo(handles)
    global vidobj;  % Video camera object.
    % Bail out if there is no video object class instantiated.
    if isempty(vidobj), return, end;
    % Switch the current graphic axes to handles.axesImage.
    % This is where we want the video to go.
    axes(handles.axesImage);
    % Reset image magnification. Required if you ever displayed an image
% in the axes that was not the same size as your webcam image.
hold off;
axis auto;  
% Get the handle to the image in the axes.
hImage = findobj(handles.axesImage, 'Type', 'image');
% Turn on the live video.
preview(vidobj, hImage);
    % Put hold on so that displaying our bounding box doesn't blow away the image.
    hold on;
    % Retrieve our x,y coordinates of the bounding box corners.
    GetImageMask(handles);
    % They have been previously set elsewhere as global variables.
    global maskVerticesXCoordinates;
    global maskVerticesYCoordinates;
    if ~(isempty(maskVerticesXCoordinates) || isempty(maskVerticesYCoordinates))
        % If the bounding box coordinates exist,
        % plot the bounding box over the live video.
        plot(maskVerticesXCoordinates, maskVerticesYCoordinates);
    end

%   stoppreview(vidobj);
 return; % from TurnOnLiveVideo
1
The very first line in the error tells you the problem. Reference to non-existent field 'txtInfo'.Augwa
So what should i do to fix this error?chonglim

1 Answers

0
votes

@Augwa is right. Your code reference to non-existent field 'txtInfo'.

Have you ever created 'txtInfo' but you deleted it before?

If so

You can have a check of the blog post below, someone has the same problem as you do.

Link => http://strivingworksmartobserver.blogspot.tw/2015/05/matlab-gui-problems.html