Matlab 使用mathwork示例创建GUI时出错

Matlab 使用mathwork示例创建GUI时出错,matlab,matlab-figure,matlab-guide,Matlab,Matlab Figure,Matlab Guide,我尝试使用mathwork中的一个示例,使用一个轴和一个打开按钮创建一个MatlabGUI。然而,它给了我这些我无法修复的错误。谁能告诉我发生了什么事 对不存在字段“txtInfo”的引用 realtime21>btnPreviewVideo\u回调行100中出错 sethandles.txtInfo,'string',errorMessage gui_mainfcn第96行出错 fevalvarargin{:} realtime21第42行出错 gui_mainfcngui_州,瓦拉金{:}

我尝试使用mathwork中的一个示例,使用一个轴和一个打开按钮创建一个MatlabGUI。然而,它给了我这些我无法修复的错误。谁能告诉我发生了什么事

对不存在字段“txtInfo”的引用

realtime21>btnPreviewVideo\u回调行100中出错 sethandles.txtInfo,'string',errorMessage

gui_mainfcn第96行出错 fevalvarargin{:}

realtime21第42行出错 gui_mainfcngui_州,瓦拉金{:}

错误 @hObject,eventdatarealtime21'btnPreviewVideo_回调',hObject,eventdata,guidatahObject

计算uicontrol回调时出错

代码

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

@奥格瓦是对的。您对不存在的字段“txtInfo”的代码引用

您是否曾经创建过“txtInfo”,但之前已将其删除

如果是的话

你可以查看下面的博文,有人和你有同样的问题


Link=>

错误的第一行告诉您问题所在。对不存在的字段“txtInfo”的引用。那么我应该如何修复此错误?