Hi, I'm new to matlab. I try to load a graph to gui but keep getting these error after click the push button. I'm using matlab 2015b.
4 views (last 30 days)
Show older comments
function varargout = gui_meditation(varargin)
% GUI_MEDITATION MATLAB code for gui_meditation.fig
% GUI_MEDITATION, by itself, creates a new GUI_MEDITATION or raises the existing
% singleton*.
%
% H = GUI_MEDITATION returns the handle to a new GUI_MEDITATION or the handle to
% the existing singleton*.
%
% GUI_MEDITATION('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in GUI_MEDITATION.M with the given input arguments.
%
% GUI_MEDITATION('Property','Value',...) creates a new GUI_MEDITATION or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before gui_meditation_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to gui_meditation_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 gui_meditation
% Last Modified by GUIDE v2.5 21-Nov-2017 22:41:35
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @gui_meditation_OpeningFcn, ...
'gui_OutputFcn', @gui_meditation_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 gui_meditation is made visible.
function gui_meditation_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 gui_meditation (see VARARGIN)
% Choose default command line output for gui_meditation
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes gui_meditation wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = gui_meditation_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 Start.
function Start_Callback(hObject, eventdata, handles)
% hObject handle to Start (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
function varargout = gui_meditation(varargin)
% GUI_MEDITATION MATLAB code for gui_meditation.fig
% GUI_MEDITATION, by itself, creates a new GUI_MEDITATION or raises the existing
% singleton*.
%
% H = GUI_MEDITATION returns the handle to a new GUI_MEDITATION or the handle to
% the existing singleton*.
%
% GUI_MEDITATION('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in GUI_MEDITATION.M with the given input arguments.
%
% GUI_MEDITATION('Property','Value',...) creates a new GUI_MEDITATION or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before gui_meditation_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to gui_meditation_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 gui_meditation
% Last Modified by GUIDE v2.5 07-Nov-2017 00:02:16
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @gui_meditation_OpeningFcn, ...
'gui_OutputFcn', @gui_meditation_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 gui_meditation is made visible.
function gui_meditation_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 gui_meditation (see VARARGIN)
% Choose default command line output for gui_meditation
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes gui_meditation wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = gui_meditation_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 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)
%Clear Screen
clc;
%Clear Variables
clear all;
%Close figures
close all;
%Preallocate buffer
data_med = zeros(1,256);
%Comport Selection
portnum1 = 5;
%COM Port #
comPortName1 = sprintf('\\\\.\\COM%d', portnum1);
% Baud rate for use with TG_Connect() and TG_SetBaudrate().
TG_BAUD_115200 = 115200;
% Data format for use with TG_Connect() and TG_SetDataFormat().
TG_STREAM_PACKETS = 0;
% Data type that can be requested from TG_GetValue().
TG_DATA_MEDITATION = 3;
%load thinkgear dll
loadlibrary('Thinkgear.dll');
%To display in Command Window
fprintf('Thinkgear.dll loaded\n');
%get dll version
dllVersion = calllib('Thinkgear', 'TG_GetDriverVersion');
%To display in command window
fprintf('ThinkGear DLL version: %d\n', dllVersion );
% Get a connection ID handle to ThinkGear
connectionId1 = calllib('Thinkgear', 'TG_GetNewConnectionId');
if ( connectionId1 < 0 )
error( sprintf( 'ERROR: TG_GetNewConnectionId() returned %d.\n', connectionId1 ) );
end;
% Attempt to connect the connection ID handle to serial port "COM3"
errCode = calllib('Thinkgear', 'TG_Connect', connectionId1,comPortName1,TG_BAUD_115200,TG_STREAM_PACKETS );
if ( errCode < 0 )
error( sprintf( 'ERROR: TG_Connect() returned %d.\n', errCode ) );
end
fprintf( 'Connected. Reading Packets...\n' );
i=0;
j=0;
%To display in Command Window
disp('Reading Brainwaves');
figure;
while i < 20
if (calllib('Thinkgear','TG_ReadPackets',connectionId1,1) == 1) %if a packet was read...
if (calllib('Thinkgear','TG_GetValueStatus',connectionId1,TG_DATA_MEDITATION ) ~= 0)
j = j + 1;
i = i + 1;
%Read attention Valus from thinkgear packets
data_med(j) = calllib('Thinkgear','TG_GetValue',connectionId1,TG_DATA_MEDITATION );
%To display in Command Window
disp(data_med(j));
%Plot Graph
plot(data_med);
title('Meditation');
%Delay to display graph
pause(1);
end
end
end
%To display in Command Window
disp('Loop Completed')
%Release the comm port
calllib('Thinkgear', 'TG_FreeConnection', connectionId1 );
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
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
...............................
these errors appear.
>> gui_meditation
Error: File: gui_meditation.m Line: 83 Column: 22
Function with duplicate name "gui_meditation" cannot be defined.
Error: File: gui_meditation.m Line: 83 Column: 22
Function with duplicate name "gui_meditation" cannot be defined.
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)gui_meditation('edit1_CreateFcn',hObject,eventdata,guidata(hObject))
Error: File: gui_meditation.m Line: 83 Column: 22
Function with duplicate name "gui_meditation" cannot be defined.
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)gui_meditation('Start_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback
>> matlab.graphics.internal.figfile.FigFile.read
The class matlab.graphics.internal.figfile.FigFile has no Constant property or Static method named 'read'.
>> gui_meditation
Error: File: gui_meditation.m Line: 83 Column: 22
Function with duplicate name "gui_meditation" cannot be defined.
>> gui_meditation
Error: File: gui_meditation.m Line: 83 Column: 22
Function with duplicate name "gui_meditation" cannot be defined.
Error: File: gui_meditation.m Line: 83 Column: 22
Function with duplicate name "gui_meditation" cannot be defined.
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)gui_meditation('Start_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback
Error: File: gui_meditation.m Line: 83 Column: 22
Function with duplicate name "gui_meditation" cannot be defined.
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)gui_meditation('Start_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback
Error: File: gui_meditation.m Line: 83 Column: 22
Function with duplicate name "gui_meditation" cannot be defined.
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)gui_meditation('Start_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback
>>
0 Comments
Answers (1)
Walter Roberson
on 28 Nov 2017
Delete everything up to line 82, the line before the second "function gui_meditation"
See Also
Categories
Find more on Graphics Object Properties 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!