function varargout = Models_Creation(varargin)
% MODELS_CREATION M-file for Models_Creation.fig
% MODELS_CREATION, by itself, creates a new MODELS_CREATION or raises the existing
% singleton*.
%
% H = MODELS_CREATION returns the handle to a new MODELS_CREATION or the handle to
% the existing singleton*.
%
% MODELS_CREATION('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in MODELS_CREATION.M with the given input arguments.
%
% MODELS_CREATION('Property','Value',...) creates a new MODELS_CREATION or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before Models_Creation_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to Models_Creation_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 Models_Creation
% Last Modified by GUIDE v2.5 01-Feb-2007 09:09:03
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Models_Creation_OpeningFcn, ...
'gui_OutputFcn', @Models_Creation_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 Models_Creation is made visible.
function Models_Creation_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 Models_Creation (see VARARGIN)
% Choose default command line output for Models_Creation
handles.output = hObject;
addpath(genpath(fullfile(matlabroot,'toolbox\LSSVM\LS-SVMlab1.5')));
addpath(genpath(fullfile(matlabroot,'toolbox\Pedelecs')));
%initialization of the pedelec data
handles.Name=0;
handles.Gear=0;
handles.Z=0;
handles.sheet=1;
handles.Model=0;
handles.Model2=0;
%handles.data=[]; %trainings- and testdata for all modes
%handles.pmodels=[]; %models for all modes
%handles.RMSE=[]; %RMSE for all modes
%handles.DestiFolder='nothing';
%handles.DataFile=0;%absolutely not done!
handles.fileput=0; % to check if there's any input
handles.folderput=0;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes Models_Creation wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = Models_Creation_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;
function DataFile_Callback(hObject, eventdata, handles)
% hObject handle to DataFile (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 DataFile as text
% str2double(get(hObject,'String')) returns contents of DataFile as a double
a=get(hObject,'string');
set(handles.DataFile,'string',a);
handles.fileput=1;
guidata(hObject,handles);
% --- Executes during object creation, after setting all properties.
function DataFile_CreateFcn(hObject, eventdata, handles)
% hObject handle to DataFile (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 DestiFolder_Callback(hObject, eventdata, handles)
% hObject handle to DestiFolder (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 DestiFolder as text
% str2double(get(hObject,'String')) returns contents of DestiFolder as a double
a=get(hObject,'string');
set(handles.DestiFolder,'string',a);
handles.folderput=1;
guidata(hObject,handles);
% --- Executes during object creation, after setting all properties.
function DestiFolder_CreateFcn(hObject, eventdata, handles)
% hObject handle to DestiFolder (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
% --- Executes on button press in FileBrowse.
function FileBrowse_Callback(hObject, eventdata, handles)
% hObject handle to FileBrowse (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[FileName,PathName] = uigetfile('*.xls','Select the exel-file');
TotalFilename=fullfile(PathName,FileName);
set(handles.DataFile,'string',TotalFilename);
handles.fileput=1;
%handles.DataFile=handles.FileBrowse;
guidata(hObject,handles);
% --- Executes on button press in DestiFolderBrowse.
function FolderBrowse_Callback(hObject, eventdata, handles)
% hObject handle to FolderBrowse (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% handles.DestiFolder
% dirk=get(handles.DestiFolder,'string');
DirName = uigetdir('C:\','Select the directory where you want to put the models');
handles.folderput=1;
set(handles.DestiFolder,'string',DirName);
guidata(hObject,handles);
function Name_Callback(hObject, eventdata, handles)
% hObject handle to Name (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 Name as text
% str2double(get(hObject,'String')) returns contents of Name as a double
handles.Name = get(hObject,'string');
guidata(hObject,handles);
% --- Executes during object creation, after setting all properties.
function Name_CreateFcn(hObject, eventdata, handles)
% hObject handle to Name (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 Z_Callback(hObject, eventdata, handles)
% hObject handle to Z (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 Z as text
% str2double(get(hObject,'String')) returns contents of Z as a double
Z = str2double(get(hObject,'string'));
if not(isnumeric(Z))
errordlg('You must enter a numeric value','Bad Input','modal')
end
handles.Z=Z;
guidata(hObject,handles);
% --- Executes during object creation, after setting all properties.
function Z_CreateFcn(hObject, eventdata, handles)
% hObject handle to Z (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 Gear_Callback(hObject, eventdata, handles)
% hObject handle to Gear (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 Gear as text
% str2double(get(hObject,'String')) returns contents of Gear as a double
G = str2double(get(hObject,'string'));
if not(isnumeric(G))
errordlg('You must enter a numeric value','Bad Input','modal')
end
handles.Gear=G;
guidata(hObject,handles);
% --- Executes during object creation, after setting all properties.
function Gear_CreateFcn(hObject, eventdata, handles)
% hObject handle to Gear (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
% --- Executes on button press in Performance.
function Performance_Callback(hObject, eventdata, handles)
% hObject handle to Performance (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%Check if there are any models created any
button=questdlg(['Before looking at the plots, the creation of all models is recommended. Continue anyway?']);
if strcmp(button,'No')
elseif strcmp(button,'Cancel')
disp('cancelled')
else
run('Performance_Plots')
end
% --- Executes on button press in Createmodel.
function Createmodel_Callback(hObject, eventdata, handles)
% hObject handle to Createmodel (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%
allright=0;
%Conditions to be fullfilled before starting the models_creation
%Necessary to warn if a file called 'data' exists already
newpath=get(handles.DestiFolder,'string');
probfile=fullfile(newpath,'pedelec.mat');%look for the 'folder/pedelec.mat'
a=which(probfile);%which is the nearest modelZA.mat file
%exclude that other pedelec.mat files in other folders are used
b=probfile;
if handles.fileput==0
errordlg('Please select an excel file with measurement data','Bad Input','modal')
elseif handles.Model==0
errordlg('Please choose the model you want to create from the pedelecfile','Bad Input','modal')
elseif handles.folderput==0
errordlg('Please choose a folder where you want to save the models','Bad Input','modal')
elseif isnumeric(handles.Name);
errordlg('Please fill in a pedelec name','Bad Input','modal')
elseif handles.Z==0
errordlg('Please give the Z ratio of the pedelec','Bad Input','modal')
elseif handles.Gear==0
errordlg('Please give the gearnumber of the pedelec','Bad Input','modal')
elseif exist(probfile)~=0
%and(exist(probfile)~=0,strcmp(a,b)) %some problem with this one
%chance for overwriting really exists, so warn!
probdata=load(probfile); %nog aan te passen aan nieuwe pedelecstructure uit save-deel
if isfield(probdata,'vTcModels')
if isempty(probdata.vTcModels)
modellist=[];
else
modellist=fieldnames(probdata.vTcModels);
modellist=cellstr(modellist);
modellist=modellist';
end
handles.data=probdata.vFtData;
handles.RMSE=probdata.vTcRMSE;
handles.pmodels=probdata.vTcModels;
button=questdlg(['These models were already found in the destination folder: ' modellist,' Continue anyway?']);
if strcmp(button,'No')
elseif strcmp(button,'Cancel')
disp('cancelled')
else
allright=1;
end
else
button=questdlg(['There were no Ft(v,Tc) models found in the destination folder! Continue anyway?']);
if strcmp(button,'No')
elseif strcmp(button,'Cancel')
disp('cancelled')
else
allright=1;
handles.data=[];
handles.RMSE=[];
handles.pmodels=[];
end
end
else
probdata=[];
allright=1;
handles.data=[];
handles.RMSE=[];
handles.pmodels=[];
end
%all starting conditions are fulfilled, do you really want to start?
%Warn the users for the long time it may take to make a model
if allright==1
button=questdlg('Creating a model may take a while, are you sure you want to try this out?');
if strcmp(button,'No')
elseif strcmp(button,'Cancel')
disp('cancelled model creation')
else
disp('Creating model')
%the creation may start!
%split up data from pedelecfile between training and testdata (75%-25%)
%and save them as variable pedelec.mat
%pedelec.mat contains vFtData.mode.(tra/test)data
xlsfile=get(handles.DataFile,'string');
sheet=handles.sheet;
[trad testd]=Readdatamode(xlsfile,sheet);
%handles.mode
mode=handles.Model;
dirk = cd; %save the current directory
folder=get(handles.DestiFolder,'string');
hulp.tradata=trad;
hulp.testdata=testd;
vTcData=handles.data;
if strcmp(mode,'KSI')~=1 %for the ksi model the trainings and testdata of the Ftmodels are used.
vTcData = setfield(vTcData,mode,hulp);%Put the calculated trainings and testdata in the vFtData.mode field
end
handles.data=vTcData;
Z=handles.Z;
%Create the LSSVMmodel from the tradata
if strcmp(mode,'ETA') %modelling eta is different from other models
axes(handles.axes2);
ETAmodel=createLSSVMeta(trad,Z);
%ETAmodel=1; %only for testing
vTcModels=handles.pmodels;
vTcModels=setfield(vTcModels,mode,ETAmodel);%Put the calculated model in the vTcModels.mode field
handles.pmodels=vTcModels;
%modelling the RMSEeta is different from other
%models
etaRMSE=RMSEcalculETA(ETAmodel,testd,Z);
%etaRMSE=1; %only for testing
vTcRMSE=handles.RMSE;
vTcRMSE=setfield(vTcRMSE,mode,etaRMSE*100);%Put the calculated RMSE in the RMSE.mode field
elseif strcmp(mode,'KSI') %modelling ksi
if length(fieldnames(probdata.vTcRMSE))>1
vTcModels=handles.pmodels
testdataZA=handles.data.ZA.testdata;
vTcRMSE=handles.RMSE;
KSImodel=createKSImodels(vTcModels);
ksiRMSE=RMSEcalculKSI(KSImodel,testdataZA,vTcRMSE,vTcModels)
vTcModels=setfield(vTcModels,'KSI',KSImodel);%Put the calculated model in the vTcModels.mode field
handles.pmodels=vTcModels;
vTcRMSE=setfield(vTcRMSE,mode,ksiRMSE*100);
else errordlg('Please create first the models for the available motor assistance modes','bad input','modal')
end
else %all assistance mode models can be treated as follows
axes(handles.axes2);
thismodel=createLSSVMmodel(trad);
%thismodel=1; %use this nonsense to avoid the long calculation time
vTcModels=handles.pmodels;
vTcModels=setfield(vTcModels,mode,thismodel);%Put the calculated model in the vTcModels.mode field
handles.pmodels=vTcModels;
%Calculate the RMSE_LSSVM
thisRMSE=RMSEcalcul(thismodel,testd);
%thisRMSE=1; %use this nonsense to avoid the long calculation time
vTcRMSE=handles.RMSE;
vTcRMSE=setfield(vTcRMSE,mode,thisRMSE);%Put the calculated RMSE in the RMSE.mode field
end
%save all the variables
gear=num2str(handles.Gear);%save name and gearnumber for the pedelec
pname=[handles.Name gear];
pZ=num2str(handles.Z);
%save also the variables of model 2 if any
if isfield(probdata,'vFtRMSE')
vFtRMSE=getfield(probdata,'vFtRMSE');
vFtData=getfield(probdata,'vFtData');
vFtModels=getfield(probdata,'vFtModels');
else
vFtRMSE=[];
vFtData=[];
vFtModels=[];
end
cd(folder)
save('pedelec','vTcModels','vFtModels','vTcData','vFtData','vTcRMSE','vFtRMSE','pZ','pname') %save('pedelec','var1','var2') %erases when recalled
cd(dirk)
%display the RMSE in the RMSE box
%The names of the RMSEs
allmodellist=fieldnames(vTcModels);
%allmodellist=cellstr(allmodellist);
r1=0;
r2=0;
rest=[]; %wasn't here in the first working version
if isfield(vTcModels,'KSI')
for k=1:length(allmodellist)
if strcmp(allmodellist(k),'KSI')==1
r1=1;
r3=k;
else
if r1==1
r2=r2+1;
rest(r2)=allmodellist(k);
end
end
end
newallmodellist=[allmodellist(1:r3-1);'ksiMAe';'ksiMAn';'ksiMAp'; rest];
else
newallmodellist=allmodellist;
end
%The units of the RMSEs
for k=1:length(newallmodellist)
if strcmp(newallmodellist(k),'ZA')
unit(k)=cellstr('[N]');
bz(k)=' ';
elseif strcmp(newallmodellist(k),'MAe')
unit(k)=cellstr('[N]');
bz(k)=' ';
elseif strcmp(newallmodellist(k),'MAn')
unit(k)=cellstr('[N]');
bz(k)=' ';
elseif strcmp(newallmodellist(k),'MAp')
unit(k)=cellstr('[N]');
bz(k)=' ';
else
unit(k)=cellstr('[%]');
bz(k)=' ';
end
end
listlist=[char(newallmodellist) bz' char(unit')];
allRMSElist=struct2cell(vTcRMSE);
set(handles.modelbox,'string',listlist);
set(handles.RMSEbox,'string',allRMSElist);
%set(handles.RMSEbox,'string',[allmodellist allRMSElist])
msgbox('model is created','finished')
end
end
guidata(hObject,handles);
% --- Executes during object creation, after setting all properties.
function Createmodel_CreateFcn(hObject, eventdata, handles)
% hObject handle to Createmodel (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
function sheet_Callback(hObject, eventdata, handles)
% hObject handle to sheet (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 sheet as text
% str2double(get(hObject,'String')) returns contents of sheet as a double
sheet = str2double(get(hObject,'string'));
if not(isnumeric(sheet))
errordlg('You must enter the sheet number of the data excelfile','Bad Input','modal')
end
handles.sheet=sheet;
guidata(hObject,handles);
% --- Executes during object creation, after setting all properties.
function sheet_CreateFcn(hObject, eventdata, handles)
% hObject handle to sheet (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 Model_SelectionChangeFcn(hObject, eventdata, handles)
% hObject handle to Model (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%a=get(hObject,'tag')
switch get(hObject,'tag') % Get Tag of selected object
case 'ModelZA'
% code piece when radiobutton1 is selected goes here
handles.Model='ZA';
case 'ModelMAe'
% code piece when radiobutton2 is selected goes here
handles.Model='MAe';
case 'ModelMAn'
handles.Model='MAn';
case 'ModelMAp'
handles.Model='MAp';
case 'ModelETA'
handles.Model='ETA';
case 'ModelKSI'
%handles.Model=['KSIMAe';'KSIMAn';'KSIMAp'];
handles.Model='KSI';
end
guidata(hObject,handles);
function RMSEbox_Callback(hObject, eventdata, handles)
% hObject handle to RMSEbox (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 RMSEbox as text
% str2double(get(hObject,'String')) returns contents of RMSEbox as a double
% --- Executes during object creation, after setting all properties.
function RMSEbox_CreateFcn(hObject, eventdata, handles)
% hObject handle to RMSEbox (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 modelbox_Callback(hObject, eventdata, handles)
% hObject handle to modelbox (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 modelbox as text
% str2double(get(hObject,'String')) returns contents of modelbox as a double
% --- Executes during object creation, after setting all properties.
function modelbox_CreateFcn(hObject, eventdata, handles)
% hObject handle to modelbox (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 RMSEbox2_Callback(hObject, eventdata, handles)
% hObject handle to RMSEbox2 (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 RMSEbox2 as text
% str2double(get(hObject,'String')) returns contents of RMSEbox2 as a double
% --- Executes during object creation, after setting all properties.
function RMSEbox2_CreateFcn(hObject, eventdata, handles)
% hObject handle to RMSEbox2 (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 modelbox2_Callback(hObject, eventdata, handles)
% hObject handle to modelbox2 (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 modelbox2 as text
% str2double(get(hObject,'String')) returns contents of modelbox2 as a double
% --- Executes during object creation, after setting all properties.
function modelbox2_CreateFcn(hObject, eventdata, handles)
% hObject handle to modelbox2 (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 Model2_SelectionChangeFcn(hObject, eventdata, handles)
% hObject handle to Model2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
switch get(hObject,'tag') % Get Tag of selected object
case 'ZA2'
% code piece when radiobutton1 is selected goes here
handles.Model2='ZA';
case 'MAe2'
% code piece when radiobutton2 is selected goes here
handles.Model2='MAe';
case 'MAn2'
handles.Model2='MAn';
case 'MAp2'
handles.Model2='MAp';
end
guidata(hObject,handles);
% --- Executes on button press in Createmodel2.
function Createmodel2_Callback(hObject, eventdata, handles)
% hObject handle to Createmodel2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
allright=0;
%Conditions to be fullfilled before starting the models_creation
%Necessary to warn if a file called 'data' exists already
newpath=get(handles.DestiFolder,'string');
probfile=fullfile(newpath,'pedelec.mat');%look for the 'folder/pedelec.mat'
a=which(probfile);%which is the nearest modelZA.mat file
%exclude that other pedelec.mat files in other folders are used
b=probfile;
if handles.fileput==0
errordlg('Please select an excel file with measurement data','Bad Input','modal')
elseif handles.Model2==0
errordlg('Please choose the model you want to create from the datafile','Bad Input','modal')
elseif handles.folderput==0
errordlg('Please choose a folder where you want to save the models','Bad Input','modal')
elseif isnumeric(handles.Name);
errordlg('Please fill in a pedelec name','Bad Input','modal')
elseif handles.Z==0
errordlg('Please give the Z ratio of the pedelec','Bad Input','modal')
elseif handles.Gear==0
errordlg('Please give the gearnumber of the pedelec','Bad Input','modal')
elseif exist(probfile)~=0
%and(exist(probfile)~=0,strcmp(a,b)) %some problem with this one
%chance for overwriting really exists, so warn!
probdata=load(probfile); %nog aan te passen aan nieuwe datastructure uit save-deel
if isfield(probdata,'vFtModels')
if isempty(probdata.vFtModels)
modellist=[];
else
modellist=fieldnames(probdata.vFtModels);
modellist=cellstr(modellist);
modellist=modellist';
end
handles.data2=probdata.vFtData;
handles.RMSE2=probdata.vFtRMSE;
handles.pmodels2=probdata.vFtModels;
button=questdlg(['These Tc(v,Ft) models were already found in the destination folder: ' modellist,' Continue anyway?']);
if strcmp(button,'No')
elseif strcmp(button,'Cancel')
disp('Cancelled')
else
allright=1;
end
else
button=questdlg(['There were no Tc(v,Ft) models found in the destination folder! Continue anyway?']);
if strcmp(button,'No')
elseif strcmp(button,'Cancel')
disp('cancelled')
else
allright=1;
handles.data2=[];
handles.RMSE2=[];
handles.pmodels2=[];
end
end
else
probdata=[];
allright=1;
handles.data2=[];
handles.RMSE2=[];
handles.pmodels2=[];
end
%all starting conditions are fulfilled, do you really want to start?
%Warn the users for the long time it may take to make a model
if allright==1
button=questdlg('Creating a model may take a while, are you sure you want to try this out?');
if strcmp(button,'No')
elseif strcmp(button,'Cancel')
disp('cancelled model creation')
else
disp('Creating model')
%the creation may start!
%split up data from datafile between training and testdata (75%-25%)
%and save them as variable pedelec.mat
%pedelec.mat contains vFtData.mode.(tra/test)data
xlsfile=get(handles.DataFile,'string');
sheet=handles.sheet;
[trad testd]=Readdatamode2(xlsfile,sheet);
%handles.mode
mode2=handles.Model2;
dirk = cd; %save the current directory
folder=get(handles.DestiFolder,'string');
hulp.tradata=trad;
hulp.testdata=testd;
vFtData=handles.data2;
vFtData = setfield(vFtData,mode2,hulp);%Put the calculated trainings and testdata in the vFtData.mode field
handles.data2=vFtData;
Z=handles.Z;
%Create the LSSVMmodel from the tradata
%all assistance mode models can be treated as follows
axes(handles.axes3);
thismodel=createLSSVMmodel(trad);
%thismodel=1; %use this nonsense to avoid the long calculation time
vFtModels=handles.pmodels2;
vFtModels=setfield(vFtModels,mode2,thismodel);%Put the calculated model in the vFtModels.mode field
handles.pmodels2=vFtModels;
%Calculate the RMSE_LSSVM
thisRMSE=RMSEcalcul(thismodel,testd);
%thisRMSE=1; %use this nonsense to avoid the long calculation time
vFtRMSE=handles.RMSE2;
vFtRMSE=setfield(vFtRMSE,mode2,thisRMSE)%Put the calculated RMSE in the RMSE.mode field
%save all the variables
gear=num2str(handles.Gear);%save name and gearnumber for the pedelec
pname=[handles.Name gear];
pZ=num2str(handles.Z);
%save also the model 1 types
if isfield(probdata,'vTcRMSE')
vTcRMSE=getfield(probdata,'vTcRMSE');
vTcData=getfield(probdata,'vTcData');
vTcModels=getfield(probdata,'vTcModels');
else
vTcRMSE=[];
vTcData=[];
vTcModels=[];
end
cd(folder)
save('pedelec','vFtModels','vFtData','vTcData','vTcRMSE','vFtRMSE','vTcModels','pZ','pname') %save('data','var1','var2') %erases when recalled
cd(dirk)
%display the RMSE in the RMSE box
%The names of the RMSEs
allmodellist=fieldnames(vFtModels);
allmodellist=cellstr(allmodellist);
%The units of the RMSEs
for k=1:length(allmodellist)
unit(k)=cellstr('[Nm]');
bz(k)=' ';
end
listlist=[char(allmodellist) bz' char(unit')];
allRMSElist=struct2cell(vFtRMSE);
set(handles.modelbox2,'string',listlist);
set(handles.RMSEbox2,'string',allRMSElist);
%set(handles.RMSEbox,'string',[allmodellist allRMSElist])
msgbox('model is created','finished')
end
end
guidata(hObject,handles);
% --- Executes during object creation, after setting all properties.
function figure1_CreateFcn(hObject, eventdata, handles)
% hObject handle to figure1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% --- Executes during object creation, after setting all properties.
function Model2_CreateFcn(hObject, eventdata, handles)
% hObject handle to Model2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called