Problem With SVMTRAIN Function

2 views (last 30 days)
I have an example program of IrisData; I have tested this program in another PC and runs with any problem, but in a laptop, the program always throws a problem with that function. My Code is:
function varargout = svm(varargin)
% SVM MATLAB code for svm.fig
% SVM, by itself, creates a new SVM or raises the existing
% singleton*.
%
% H = SVM returns the handle to a new SVM or the handle to
% the existing singleton*.
%
% SVM('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in SVM.M with the given input arguments.
%
% SVM('Property','Value',...) creates a new SVM or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before svm_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to svm_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 svm
% Last Modified by GUIDE v2.5 12-Sep-2014 04:50:47
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @svm_OpeningFcn, ...
'gui_OutputFcn', @svm_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 svm is made visible.
function svm_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 svm (see VARARGIN)
% Choose default command line output for svm
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes svm wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = svm_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 selection change in Kernel.
function Kernel_Callback(hObject, eventdata, handles)
% hObject handle to Kernel (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns Kernel contents as cell array
% contents{get(hObject,'Value')} returns selected item from Kernel
% --- Executes during object creation, after setting all properties.
function Kernel_CreateFcn(hObject, eventdata, handles)
% hObject handle to Kernel (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox 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
% --- Executes on button press in Entrenar.
function Entrenar_Callback(hObject, eventdata, handles)
Wilt=load ('saseWilt');
global maquina1;global maquina2;
Condicion=0;
kernel = get(handles.Kernel,'Value');
switch kernel
case 1
set(handles.Efectividad, 'String', 'Elige una opción valida');
Condicion=1;
case 2
opcKernel = 'linear';
case 3
opcKernel = 'quadratic';
case 4
opcKernel = 'polynomial';
case 5
opcKernel = 'rbf';
case 6
opcKernel = 'mlp';
end
if Condicion==0
qp_opts = optimset('MaxIter',100000);
maquina1 = svmtrain(Wilt.Datos,Wilt.sanos, 'kernel_func', opcKernel,'options',qp_opts);
maquina2 = svmtrain(Wilt.Datos,Wilt.enfermos, 'kernel_func', opcKernel,'options',qp_opts);
set(handles.Efectividad,'String','La efectividad es:');
correcto = 0;
for i = 1:4839
classe(1)= svmclassify(maquina1, Wilt.Datos(i,:));
classe(2) = svmclassify(maquina2, Wilt.Datos(i,:));
if classe == Wilt.salida(i,:)
correcto = correcto + 1;
end
end
D1=get(handles.G1,'Value');
svmtrain(Wilt.Datos(:,D1-1:D1)',Wilt.sanos(:,1),'kernel_func', opcKernel, 'ShowPlot',true,'options',qp_opts);
porcentaje = (correcto*100)/4839;
set(handles.Efectividad1, 'String', sprintf('%.4f %d', porcentaje));
end
% --- Executes on selection change in G1.
function G1_Callback(hObject, eventdata, handles)
% hObject handle to G1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns G1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from G1
% --- Executes during object creation, after setting all properties.
function G1_CreateFcn(hObject, eventdata, handles)
% hObject handle to G1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu 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
% --- Executes on selection change in G2.
function G2_Callback(hObject, eventdata, handles)
% hObject handle to G2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns G2 contents as cell array
% contents{get(hObject,'Value')} returns selected item from G2
% --- Executes during object creation, after setting all properties.
function G2_CreateFcn(hObject, eventdata, handles)
% hObject handle to G2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu 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
And the error is
Subscript indices must either be real positive integers or logicals.
Error in svm>Entrenar_Callback (line 141)
svmtrain(Wilt.Datos(:,D1-1:D1)',Wilt.sanos(:,1),'kernel_func', opcKernel, 'ShowPlot',true,'options',qp_opts);
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in svm (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)svm('Entrenar_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback

Accepted Answer

Walter Roberson
Walter Roberson on 25 Sep 2015
You get D1 from the Value property of handles.G1 . You do not appear to have any interlocks to ensure that something has been selected in G1 before the callback is run, so the Value property might be empty . If the user has selected something then they might have selected the first entry in the list, which would have value 1, so your D1 would be 1. But you then use D1-1:D1 as the index of an array: if D1 is 1 then that would be trying to access 0:1 which is not permitted because 0 is not a valid index.
  1 Comment
Enrique Mote
Enrique Mote on 25 Sep 2015
Edited: Enrique Mote on 25 Sep 2015
Thank you so much!!! I was looking for the issue so many time!! I'm sorry for my english, but it's not my native language. Thanks for your help, y have tried the program with your observation and it works!!

Sign in to comment.

More Answers (0)

Categories

Find more on Migrate GUIDE Apps 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!