function varargout = DriveCycle(varargin)
% DRIVECYCLE M-file for DriveCycle.fig
% DRIVECYCLE, by itself, creates a new DRIVECYCLE or raises the existing
% singleton*.
%
% H = DRIVECYCLE returns the handle to a new DRIVECYCLE or the handle to
% the existing singleton*.
%
% DRIVECYCLE('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in DRIVECYCLE.M with the given input arguments.
%
% DRIVECYCLE('Property','Value',...) creates a new DRIVECYCLE or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before DriveCycle_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to DriveCycle_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 DriveCycle
% Last Modified by GUIDE v2.5 23-May-2007 14:51:04
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @DriveCycle_OpeningFcn, ...
'gui_OutputFcn', @DriveCycle_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 DriveCycle is made visible.
function DriveCycle_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 DriveCycle (see VARARGIN)
% Choose default command line output for DriveCycle
handles.output = hObject;
handles.SpeedUnit=1;
handles.SlopeUnit=0;
handles.Which='fprop';
handles.mu=0.005;
handles.FA=0.7;
handles.FS=0;
handles.dt=0.5;
handles.CW=0.9;
handles.Mtot=100;
handles.EnerUnit=0;
handles.Created=0;
handles.Name='cycle';
handles.Min=1;
handles.Meas=0;
addpath(genpath(fullfile(matlabroot,'toolbox\LSSVM')));
addpath(genpath(fullfile(matlabroot,'toolbox\Pedelecs')));
addpath(genpath(fullfile(matlabroot,'toolbox\Pedelecs\drivecycles')));
handles.mode=1;
handles.folderput=0;
handles.otherplots=1;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes DriveCycle wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = DriveCycle_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 CW_Callback(hObject, eventdata, handles)
% hObject handle to CW (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 CW as text
% str2double(get(hObject,'String')) returns contents of CW as a double
c = str2double(get(hObject,'string'));
if isnan(c)
errordlg('You must enter a numeric value','Bad Input','modal')
end
handles.CW=c;
guidata(hObject,handles);
% --- Executes during object creation, after setting all properties.
function CW_CreateFcn(hObject, eventdata, handles)
% hObject handle to CW (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 Mtot_Callback(hObject, eventdata, handles)
% hObject handle to Mtot (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 Mtot as text
% str2double(get(hObject,'String')) returns contents of Mtot as a double
m = str2double(get(hObject,'string'));
if isnan(m)
errordlg('You must enter a numeric value','Bad Input','modal')
end
handles.Mtot=m;
guidata(hObject,handles);
% --- Executes during object creation, after setting all properties.
function Mtot_CreateFcn(hObject, eventdata, handles)
% hObject handle to Mtot (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 mu_Callback(hObject, eventdata, handles)
% hObject handle to mu (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 mu as text
% str2double(get(hObject,'String')) returns contents of mu as a double
mu = str2double(get(hObject,'string'));
if isnan(mu)
errordlg('You must enter a numeric value','Bad Input','modal')
end
handles.mu=mu;
guidata(hObject,handles);
% --- Executes during object creation, after setting all properties.
function mu_CreateFcn(hObject, eventdata, handles)
% hObject handle to mu (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 FA_Callback(hObject, eventdata, handles)
% hObject handle to FA (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 FA as text
% str2double(get(hObject,'String')) returns contents of FA as a double
A = str2double(get(hObject,'string'));
if isnan(A)
errordlg('You must enter a numeric value','Bad Input','modal')
end
handles.FA=A;
guidata(hObject,handles);
% --- Executes during object creation, after setting all properties.
function FA_CreateFcn(hObject, eventdata, handles)
% hObject handle to FA (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 FS_Callback(hObject, eventdata, handles)
% hObject handle to FS (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 FS as text
% str2double(get(hObject,'String')) returns contents of FS as a double
FS = str2double(get(hObject,'string'));
if isnan(FS)
errordlg('You must enter a numeric value','Bad Input','modal')
end
handles.FS=FS;
guidata(hObject,handles);
% --- Executes during object creation, after setting all properties.
function FS_CreateFcn(hObject, eventdata, handles)
% hObject handle to FS (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 dt_Callback(hObject, eventdata, handles)
% hObject handle to dt (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 dt as text
% str2double(get(hObject,'String')) returns contents of dt as a double
dt = str2double(get(hObject,'string'));
if isnan(dt)
errordlg('You must enter a numeric value','Bad Input','modal')
end
handles.dt=dt;
guidata(hObject,handles);
% --- Executes during object creation, after setting all properties.
function dt_CreateFcn(hObject, eventdata, handles)
% hObject handle to dt (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 selection change in SpeedUnit.
function SpeedUnit_Callback(hObject, eventdata, handles)
% hObject handle to SpeedUnit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns SpeedUnit contents as cell array
% contents{get(hObject,'Value')} returns selected item from SpeedUnit
val = get(hObject,'Value');
switch val
case 1
handles.SpeedUnit=1;%km/h
case 2
handles.SpeedUnit=0;%m/s
otherwise
handles.SpeedUnit=0;
end
if handles.Created==0
errordlg('Please create the cycle before changing the units','bad input','modal')
else
str=get(handles.CycleFile,'string');
n=handles.Name;
%dt=str2double(get(handles.Deltat,'string'));
dt=handles.dt;
cycle1=cycle(str,dt,n);
axes(handles.cyclaxes)
Spunit=handles.SpeedUnit;
Slunit=handles.SlopeUnit;
tss_plot(cycle1,n,Spunit,Slunit);
end
guidata(hObject,handles);
% --- Executes during object creation, after setting all properties.
function SpeedUnit_CreateFcn(hObject, eventdata, handles)
% hObject handle to SpeedUnit (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 SlopeUnit.
function SlopeUnit_Callback(hObject, eventdata, handles)
% hObject handle to SlopeUnit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns SlopeUnit contents as cell array
% contents{get(hObject,'Value')} returns selected item from SlopeUnit
val = get(hObject,'Value');
switch val
case 1
handles.SlopeUnit=0;
case 2
handles.SlopeUnit=1;
% otherwise
% set(handles_SlopeUnit,'string',0);
end
if handles.Created==0
errordlg('Please create the cycle before changing the units','bad input','modal')
else
str=get(handles.CycleFile,'string');
n=handles.Name;
%dt=str2double(get(handles.Deltat,'string'));
dt=handles.dt;
cycle1=cycle(str,dt,n);
axes(handles.cyclaxes)
Spunit=handles.SpeedUnit;
Slunit=handles.SlopeUnit;
tss_plot(cycle1,n,Spunit,Slunit);
end
guidata(hObject,handles);
% --- Executes during object creation, after setting all properties.
function SlopeUnit_CreateFcn(hObject, eventdata, handles)
% hObject handle to SlopeUnit (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
function CycleFile_Callback(hObject, eventdata, handles)
% hObject handle to CycleFile (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 CycleFile as text
% str2double(get(hObject,'String')) returns contents of CycleFile as a double
str = get(hObject,'string');
% if ischar(str)
% errordlg('You must enter a string','Bad Input','modal')
% end
%handles.CycleFile=str;
set(handles.CycleFile,'string',str);
guidata(hObject, handles);
% --- Executes during object creation, after setting all properties.
function CycleFile_CreateFcn(hObject, eventdata, handles)
% hObject handle to CycleFile (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 PedelecFolder_Callback(hObject, eventdata, handles)
% hObject handle to PedelecFolder (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 PedelecFolder as text
% str2double(get(hObject,'String')) returns contents of PedelecFolder as a double
a=get(hObject,'string');
set(handles.PedelecFolder,'string',a);
handles.folderput=1;
guidata(hObject,handles);
% --- Executes during object creation, after setting all properties.
function PedelecFolder_CreateFcn(hObject, eventdata, handles)
% hObject handle to PedelecFolder (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 BrowseFile.
function BrowseFile_Callback(hObject, eventdata, handles)
% hObject handle to BrowseFile (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);
handles.BrowseFile=TotalFilename;
set(handles.CycleFile,'string',TotalFilename);
guidata(hObject,handles);
% --- Executes on button press in BrowseFolder.
function BrowseFolder_Callback(hObject, eventdata, handles)
% hObject handle to BrowseFolder (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
DirName = uigetdir('C:\','Select the directory where the pedelec.mat file is stored');
handles.folderput=1;
set(handles.PedelecFolder,'string',DirName);
guidata(hObject,handles);
function MinEner_Callback(hObject, eventdata, handles)
% hObject handle to MinEner (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 MinEner as text
% str2double(get(hObject,'String')) returns contents of MinEner as a double
% --- Executes during object creation, after setting all properties.
function MinEner_CreateFcn(hObject, eventdata, handles)
% hObject handle to MinEner (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 MinPower_Callback(hObject, eventdata, handles)
% hObject handle to MinPower (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 MinPower as text
% str2double(get(hObject,'String')) returns contents of MinPower as a double
% --- Executes during object creation, after setting all properties.
function MinPower_CreateFcn(hObject, eventdata, handles)
% hObject handle to MinPower (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 MeasEner_Callback(hObject, eventdata, handles)
% hObject handle to MeasEner (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 MeasEner as text
% str2double(get(hObject,'String')) returns contents of MeasEner as a double
% --- Executes during object creation, after setting all properties.
function MeasEner_CreateFcn(hObject, eventdata, handles)
% hObject handle to MeasEner (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 MeasPower_Callback(hObject, eventdata, handles)
% hObject handle to MeasPower (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 MeasPower as text
% str2double(get(hObject,'String')) returns contents of MeasPower as a double
% --- Executes during object creation, after setting all properties.
function MeasPower_CreateFcn(hObject, eventdata, handles)
% hObject handle to MeasPower (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 selection change in EnerUnit.
function EnerUnit_Callback(hObject, eventdata, handles)
% hObject handle to EnerUnit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns EnerUnit contents as cell array
% contents{get(hObject,'Value')} returns selected item from EnerUnit
val = get(hObject,'Value');
switch val
case 1
handles.EnerUnit=0;
set(handles.MinEner,'string',handles.EnerPowerCal(2))
case 2
handles.EnerUnit=1;
set(handles.MinEner,'string',handles.EnerPowerCal(1))
end
guidata(hObject, handles);
% --- Executes during object creation, after setting all properties.
function EnerUnit_CreateFcn(hObject, eventdata, handles)
% hObject handle to EnerUnit (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 Which.
function Which_Callback(hObject, eventdata, handles)
% hObject handle to Which (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns Which contents as cell array
% contents{get(hObject,'Value')} returns selected item from Which
val = get(hObject,'Value');
switch val
case 1
handles.Which='fprop';
case 2
handles.Which='ftpos';
case 3
handles.Which='fair';
case 4
handles.Which='frol';
case 5
handles.Which='fslope';
case 6
handles.Which='Tc';
end
guidata(hObject,handles);
% --- Executes during object creation, after setting all properties.
function Which_CreateFcn(hObject, eventdata, handles)
% hObject handle to Which (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 button press in Min.
function Min_Callback(hObject, eventdata, handles)
% hObject handle to Min (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of Min
handles.Min=get(hObject,'Value');
guidata(hObject,handles);
% --- Executes on button press in CreateCycle.
function CreateCycle_Callback(hObject, eventdata, handles)
% hObject handle to CreateCycle (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%what is asked?
%if only the minimal values are crossed
str=get(handles.CycleFile,'string');
n=handles.Name;
%dt=str2double(get(handles.Deltat,'string'));
dt=handles.dt;
cycle1=cycle(str,dt,n);
axes(handles.cyclaxes)
Spunit=handles.SpeedUnit;
Slunit=handles.SlopeUnit;
tss_plot(cycle1,n,Spunit,Slunit);
handles.CreateCycle=cycle1;
handles.Created=1; %tells if the cycle was already created
%if only the measured values are crossed
%figure(1)
%tss_plot(cycle1,n,Spunit,Slunit);
%saving cycledata in the folder of the CYCLE
A=handles.FA;
v=handles.FS;
cw=handles.CW;
mu=handles.mu;
m=handles.Mtot;
dt=handles.dt;
%Forces=cycleforces(cycle1,A,v,cw,mu,m);
Cycleforces=cycleforces(cycle1,A,v,cw,mu,m);
Cycle=cycle1;
[folder, name, ext, versn]=fileparts(get(handles.CycleFile,'string'));
dirk=cd;
cd(folder)
%save('cycledata','Cycle','Forces') %save('data','var1','var2') %erases when recalled
save('cycledata','Cycleforces')
cd(dirk)
warndlg(['The cycledata.mat is stored in ', folder]);
guidata(hObject,handles);
% --- Executes on button press in CalculF.
function CalculF_Callback(hObject, eventdata, handles)
% hObject handle to CalculF (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%when pushed CalculF one also looks for existing models in the
%PedelecFolder
if handles.folderput==0 %no given directory
errordlg('There is no directory selected to look for the pedelec datafile','Bad Input','modal')
avail=zeros(1,4);
elseif handles.folderput==1 %there is a directory given
newpath=get(handles.PedelecFolder,'string');
probfile=fullfile(newpath,'pedelec.mat');%look for the 'folder/pedelec.mat'
avail=zeros(1,4);
if exist(probfile)==0 %the dir has no pedelec.mat file
errordlg('There was no pedelec.mat file found in the given directory','Bad Input','modal')
avail=zeros(1,4);
elseif exist(probfile)~=0 %the dir has a pedelec.mat file
probdata=load(probfile);
if isfield(probdata,'vFtModels') %look for Ft(v,Tc) models and tell which of the 6 are available
%create a list with available models
modellist=fieldnames(probdata.vFtModels);
comparelist={'ZA','MAe','MAn','MAp'};
for k=1:length(comparelist)
if sum(strcmp(modellist,comparelist(k)))~=0
avail(k)=1;
else
avail(k)=0;
end
end
handles.Z=str2double(probdata.pZ);%define the models
handles.pedelec=probdata.pname(1);
else avail=zeros(1,4);
end
end
end
handles.avail=avail;
cycle=handles.CreateCycle;
A=handles.FA;
v=handles.FS;
cw=handles.CW;
mu=handles.mu;
force=handles.Which;
m=handles.Mtot;
dt=handles.dt;
calculforces=cycleforces(cycle,A,v,cw,mu,m);
cycle=handles.CreateCycle;
if strcmp(force,'Tc') %the required cyclist torque is asked
mode=handles.mode;
modename={'ZA','MAe','MAn','MAp'};
Fs=get(calculforces,'ftpos');
vs=get(cycle,'v');
t=get(cycle,'t');
Xnew=[vs Fs];
avail=handles.avail;
if avail==zeros(1,4)
errordlg('there are no pedelec models available in the pedelec.mat file','bad input','modal')
else
newpath=get(handles.PedelecFolder,'string');
probfile=fullfile(newpath,'pedelec.mat');
probdata=load(probfile);
Z=str2double(probdata.pZ);
if and(mode==1,avail(1)==1)
model=probdata.vFtModels.ZA;
elseif and(mode==2,avail(2)==1)
model=probdata.vFtModels.MAe;
elseif and(mode==3,avail(3)==1)
model=probdata.vFtModels.MAn;
elseif and(mode==4,avail(4)==1)
model=probdata.vFtModels.MAp;
else
errordlg('No model available for your request','bad input','modal')
end
%choice between minimal and measured values
if and(handles.Min==1,handles.Meas==0); %minimal values asked
axes(handles.Plotaxes)
Ts=Z*Fs;
plot(t,Ts);
tit=(['Minimal required cyclist torque to cover the cycle with Z= ', num2str(Z), 'rad/m']);
title(tit,'fontsize',12);
xlabel('time [s]','fontsize',12);
ylabel('T_c [Nm]','fontsize',12);
axis([0 max(t) -5 80]);
%calculate the minimal energy and power
[Powers Energies]=powering(calculforces);
handles.EnerPowerCal=Energies;
%handles.CalPower1=Powers;
%disp(handles.CalPower)
if handles.EnerUnit==0;
set(handles.MinEner,'string',Energies(2))
elseif handles.EnerUnit==1;
set(handles.MinEner,'string',Energies(1))
end
set(handles.MinPower,'string',Energies(3))
elseif and(handles.Min==0,handles.Meas==1); %measured values asked
Ts=simlssvm(model,Xnew);
axes(handles.Plotaxes)
plot(t,Ts);
tit=(['Required cyclist torque using ' char(handles.pedelec) ' in ' char(modename(mode)) ' mode']);
title(tit,'fontsize',12)
xlabel('time [s]','fontsize',12);
ylabel('T_c [Nm]','fontsize',12);
text(max(t)/2,80/(1.05),['Z= ', num2str(Z), 'rad/m']);
axis([0 max(t) -5 80]);
%calculate the measured energy and power
%power versus time
Ptt=Ts.*vs/(Z*3.6);
%Required energy
Wtt=0;
for i=1:length(t)-1
Wtt=Wtt+(Ptt(i+1)+Ptt(i))*dt/2;
end
WttJ=Wtt; %in Joules
Wttwh=Wtt/3600; %in Wh
Pmt=Wtt/max(t); %average power
Energies=[WttJ Wttwh Pmt];
if handles.EnerUnit==0;
set(handles.MeasEner,'string',Energies(2))
elseif handles.EnerUnit==1;
set(handles.MeasEner,'string',Energies(1))
end
set(handles.MeasPower,'string',Energies(3))
elseif and(handles.Min==1,handles.Meas==1); %both values asked
else
errordlg('Please choose between minimal or measured values','bad input','modal')
end
end
else
if handles.Meas==1 %measured values are not available
errordlg('Measured values are only displayed when the Required Cyclist Torque is asked','bad input','modal')
else
axes(handles.Plotaxes)
tf_plot(calculforces,force);
handles.CalculForces=calculforces;
end
%figure(1)
%tf_plot(calculforces,force);
end
guidata(hObject,handles);
% % --- Executes on button press in EnerPowerCal.
% function EnerPowerCal_Callback(hObject, eventdata, handles)
% % hObject handle to EnerPowerCal (see GCBO)
% % eventdata reserved - to be defined in a future version of MATLAB
% % handles structure with handles and user data (see GUIDATA)
% cycleforces=handles.CalculForces;
% [Powers Energies]=powering(cycleforces);
% handles.EnerPowerCal=Energies;
% %handles.CalPower1=Powers;
% %disp(handles.CalPower)
% if handles.EnerUnit==0;
% set(handles.MinEner,'string',Energies(2))
% elseif handles.EnerUnit==1;
% set(handles.MinEner,'string',Energies(1))
% end
% set(handles.MinPower,'string',Energies(3))
% 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
str = get(hObject,'string');
% if ischar(str)
% errordlg('You must enter a string','Bad Input','modal')
% end
handles.Name=str;
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
% --- Executes during object creation, after setting all properties.
function CalculF_CreateFcn(hObject, eventdata, handles)
% hObject handle to CalculF (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 CreateCycle_CreateFcn(hObject, eventdata, handles)
% hObject handle to CreateCycle (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 EnerPowerCal_CreateFcn(hObject, eventdata, handles)
% hObject handle to EnerPowerCal (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% --- Executes on button press in ZA.
function ZA_Callback(hObject, eventdata, handles)
% hObject handle to ZA (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of ZA
if (get(hObject,'Value') == get(hObject,'Max'))
handles.mode=1;
end
guidata(hObject, handles);
% --- Executes on button press in MAe.
function MAe_Callback(hObject, eventdata, handles)
% hObject handle to MAe (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of MAe
if (get(hObject,'Value') == get(hObject,'Max'))
handles.mode=2;
end
guidata(hObject, handles);
% --- Executes on button press in MAn.
function MAn_Callback(hObject, eventdata, handles)
% hObject handle to MAn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of MAn
if (get(hObject,'Value') == get(hObject,'Max'))
handles.mode=3;
end
guidata(hObject, handles);
% --- Executes on button press in MAp.
function MAp_Callback(hObject, eventdata, handles)
% hObject handle to MAp (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of MAp
if (get(hObject,'Value') == get(hObject,'Max'))
handles.mode=4;
end
guidata(hObject, handles);
% --- Executes on button press in Meas.
function Meas_Callback(hObject, eventdata, handles)
% hObject handle to Meas (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of Meas
handles.Meas=get(hObject,'Value');
guidata(hObject,handles);
% --- Executes on button press in Save.
function Save_Callback(hObject, eventdata, handles)
% hObject handle to Save (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% dirk = cd; %save the current directory
% folder=get(handles.PedelecFolder,'string');;
% probfile=fullfile(folder,'energies.mat');
% allright=0;
% if exist(probfile)~=0
% probdata=load(probfile); %nog aan te passen aan nieuwe datastructure uit save-deel
% if isfield(probdata,'EP')
% if isempty(probdata.EP)
% EPlist=[];
% else
% EPlist=fieldnames(probdata.EP);
% EPlist=cellstr(EPlist);
% EPlist=EPlist';
% end
% handles.parameters=probdata.EP;
% button=questdlg(['These energies were already calculated and saved: ' EPlist,' Continue anyway?']);
% if strcmp(button,'No')
% elseif strcmp(button,'Cancel')
% disp('Canceled')
% else
% allright=1;
% end
% else
% allright=1;
% handles.parameters=[];
% end
% else
% probdata=[];
% allright=1;
% handles.parameters=[];
% 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
% mode=handles.mode;
% if mode==1
% model='ZA';
% elseif mode==2
% model='MAe';
% elseif mode==3
% model='MAn';
% elseif mode==4;
% model='MAp';
% end
% En=str2double(get(handles.MinEner,'string'));
% Po=str2double(get(handles.MinPower,'string'));
% EPMin=[En Po]; %nog afhankelijk maken van eenheden
%
%
% %ook nog EPmode maken
% En=str2double(get(handles.MeasEner,'string'));
% Po=str2double(get(handles.MeasPower,'string'));
% EPMeas=[En Po]; %nog afhankelijk maken van eenheden
% EP=handles.parameters;
% EP=setfield(EP,model,EPMeas);
% EP=setfield(EP,'Min',EPMin);
% handles.parameters=EP;
% cd(folder)
% save('energies','EP') %save('data','var1','var2') %erases when recalled
% cd(dirk)
% end
guidata(hObject,handles);
% --- Executes on selection change in otherplots.
function otherplots_Callback(hObject, eventdata, handles)
% hObject handle to otherplots (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns otherplots contents as cell array
% contents{get(hObject,'Value')} returns selected item from otherplots
val = get(hObject,'Value');
switch val
case 1
handles.otherplots=1;%'Speed Duration Curve';
case 2
handles.otherplots=2;%'Weibull Distribution';
case 3
handles.otherplots=3;%'Acceleration Plot';
case 4
handles.otherplots=4;%'State Plot';
case 5
handles.otherplots=5;
end
guidata(hObject,handles);
% --- Executes during object creation, after setting all properties.
function otherplots_CreateFcn(hObject, eventdata, handles)
% hObject handle to otherplots (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 button press in Plotze.
function Plotze_Callback(hObject, eventdata, handles)
% hObject handle to Plotze (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
figure(1)
if handles.otherplots==1
monotoneplot(handles.CreateCycle,handles.SpeedUnit)
elseif handles.otherplots==2
Weibullplot(handles.CreateCycle,handles.SpeedUnit)
elseif handles.otherplots==3
Accelerationplot(handles.CreateCycle)
elseif handles.otherplots==4
Distriplot(handles.CreateCycle)
elseif handles.otherplots==5
tss_plot(handles.CreateCycle,handles.Name,handles.SpeedUnit,handles.SlopeUnit)
else errordlg('wrong choice for the extra plot','bad input','modal')
end
function Cd_Callback(hObject, eventdata, handles)
% hObject handle to Cd (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 Cd as text
% str2double(get(hObject,'String')) returns contents of Cd as a double
c = str2double(get(hObject,'string'));
if isnan(c)
errordlg('You must enter a numeric value','Bad Input','modal')
end
handles.CW=c;
guidata(hObject,handles);
% --- Executes during object creation, after setting all properties.
function Cd_CreateFcn(hObject, eventdata, handles)
% hObject handle to Cd (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 mtot_Callback(hObject, eventdata, handles)
% hObject handle to mtot (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 mtot as text
% str2double(get(hObject,'String')) returns contents of mtot as a double
m = str2double(get(hObject,'string'));
if isnan(m)
errordlg('You must enter a numeric value','Bad Input','modal')
end
handles.Mtot=m;
guidata(hObject,handles);
% --- Executes during object creation, after setting all properties.
function mtot_CreateFcn(hObject, eventdata, handles)
% hObject handle to mtot (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 Crr_Callback(hObject, eventdata, handles)
% hObject handle to Crr (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 Crr as text
% str2double(get(hObject,'String')) returns contents of Crr as a double
mu = str2double(get(hObject,'string'));
if isnan(mu)
errordlg('You must enter a numeric value','Bad Input','modal')
end
handles.mu=mu;
guidata(hObject,handles);
% --- Executes during object creation, after setting all properties.
function Crr_CreateFcn(hObject, eventdata, handles)
% hObject handle to Crr (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 speed_Callback(hObject, eventdata, handles)
% hObject handle to speed (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 speed as text
% str2double(get(hObject,'String')) returns contents of speed as a double
FS = str2double(get(hObject,'string'));
if isnan(FS)
errordlg('You must enter a numeric value','Bad Input','modal')
end
handles.FS=FS;
guidata(hObject,handles);
% --- Executes during object creation, after setting all properties.
function speed_CreateFcn(hObject, eventdata, handles)
% hObject handle to speed (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 Deltat_Callback(hObject, eventdata, handles)
% hObject handle to Deltat (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 Deltat as text
% str2double(get(hObject,'String')) returns contents of Deltat as a double
dt = str2double(get(hObject,'string'));
if isnan(dt)
errordlg('You must enter a numeric value','Bad Input','modal')
end
handles.dt=dt;
guidata(hObject,handles);
% --- Executes during object creation, after setting all properties.
function Deltat_CreateFcn(hObject, eventdata, handles)
% hObject handle to Deltat (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