i turn on and off led with mathlab by using the gui but when i push button "On" it errro

Hello. My name is kongporyou .
could you help me . I have problame with gui when i push button "On" it not work and error line 42 (underline)
Error in poryou (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)poryou('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
function varargout = poryou(varargin)
% PORYOU MATLAB code for poryou.fig
% PORYOU, by itself, creates a new PORYOU or raises the existing
% singleton*.
%
% H = PORYOU returns the handle to a new PORYOU or the handle to
% the existing singleton*.
%
% PORYOU('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in PORYOU.M with the given input arguments.
%
% PORYOU('Property','Value',...) creates a new PORYOU or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before poryou_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to poryou_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 poryou
% Last Modified by GUIDE v2.5 26-Mar-2020 13:49:29
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @poryou_OpeningFcn, ...
'gui_OutputFcn', @poryou_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 poryou is made visible.
function poryou_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 poryou (see VARARGIN)
% Choose default command line output for poryou
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
delete(instrfind({'Port'},{'COM4'}));
clear all;
clc;
global a;
a = arduino('COM4','Uno');
could you help me plese!
Thanks, best reguard.

2 Comments

Kong - you will need to show the code for pushbutton1_Callback since tht is where the error is occurring. I recommend against using global variables and suggest storing the data (that you want available between callbacks) in the handles structure. The code for the poryou_OpeningFcn would become
% --- Executes just before poryou is made visible.
function poryou_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 poryou (see VARARGIN)
% Choose default command line output for poryou
handles.output = hObject;
delete(instrfind({'Port'},{'COM4'}));
handles.a = arduino('COM4','Uno'); % <---- save the arduino object to handles
% Update handles structure
guidata(hObject, handles); % <---- update handles object

Sign in to comment.

Answers (0)

Categories

Find more on Graphics Object Properties in Help Center and File Exchange

Asked:

on 26 Mar 2020

Commented:

on 26 Mar 2020

Community Treasure Hunt

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

Start Hunting!