Dawn@4: function varargout = vs_ManualData(varargin) Dawn@4: % VS_MANUALDATA M-file for vs_ManualData.fig Dawn@4: % VS_MANUALDATA, by itself, creates a new VS_MANUALDATA or raises the existing Dawn@4: % singleton*. Dawn@4: % Dawn@4: % H = VS_MANUALDATA returns the handle to a new VS_MANUALDATA or the handle to Dawn@4: % the existing singleton*. Dawn@4: % Dawn@4: % VS_MANUALDATA('CALLBACK',hObject,eventData,handles,...) calls the local Dawn@4: % function named CALLBACK in VS_MANUALDATA.M with the given input arguments. Dawn@4: % Dawn@4: % VS_MANUALDATA('Property','Value',...) creates a new VS_MANUALDATA or raises the Dawn@4: % existing singleton*. Starting from the left, property value pairs are Dawn@4: % applied to the GUI before vs_ManualData_OpeningFcn gets called. An Dawn@4: % unrecognized property name or invalid value makes property application Dawn@4: % stop. All inputs are passed to vs_ManualData_OpeningFcn via varargin. Dawn@4: % Dawn@4: % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one Dawn@4: % instance to run (singleton)". Dawn@4: % Dawn@4: % See also: GUIDE, GUIDATA, GUIHANDLES Dawn@4: Dawn@4: % Edit the above text to modify the response to help vs_ManualData Dawn@4: Dawn@4: % Last Modified by GUIDE v2.5 22-Oct-2009 12:22:59 Dawn@4: Dawn@4: % Begin initialization code - DO NOT EDIT Dawn@4: gui_Singleton = 1; Dawn@4: gui_State = struct('gui_Name', mfilename, ... Dawn@4: 'gui_Singleton', gui_Singleton, ... Dawn@4: 'gui_OpeningFcn', @vs_ManualData_OpeningFcn, ... Dawn@4: 'gui_OutputFcn', @vs_ManualData_OutputFcn, ... Dawn@4: 'gui_LayoutFcn', [] , ... Dawn@4: 'gui_Callback', []); Dawn@4: if nargin && ischar(varargin{1}) Dawn@4: gui_State.gui_Callback = str2func(varargin{1}); Dawn@4: end Dawn@4: Dawn@4: if nargout Dawn@4: [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); Dawn@4: else Dawn@4: gui_mainfcn(gui_State, varargin{:}); Dawn@4: end Dawn@4: % End initialization code - DO NOT EDIT Dawn@4: Dawn@4: Dawn@4: % --- Executes just before vs_ManualData is made visible. Dawn@4: function vs_ManualData_OpeningFcn(hObject, eventdata, handles, varargin) Dawn@4: % This function has no output args, see OutputFcn. Dawn@4: % hObject handle to figure Dawn@4: % eventdata reserved - to be defined in a future version of MATLAB Dawn@4: % handles structure with handles and user data (see GUIDATA) Dawn@4: % varargin command line arguments to vs_ManualData (see VARARGIN) Dawn@4: Dawn@4: % Choose default command line output for vs_ManualData Dawn@4: handles.output = hObject; Dawn@4: Dawn@4: % YS: get the settings from the main figure Dawn@4: if (~isfield(handles, 'VSHandle')) Dawn@4: VSHandle = VoiceSauce; Dawn@4: handles.VSHandle = VSHandle; Dawn@4: end Dawn@4: Dawn@4: VSData = guidata(handles.VSHandle); Dawn@4: Dawn@4: set(handles.edit_wavdir, 'String', VSData.vars.MD_wavdir); Dawn@4: set(handles.edit_matdir, 'String', VSData.vars.MD_matdir); Dawn@4: Dawn@4: set(handles.checkbox_matwithwav, 'Value', VSData.vars.MD_matwithwav); Dawn@4: Dawn@4: if (VSData.vars.MD_matwithwav) Dawn@4: set(handles.edit_matdir, 'Enable', 'Off'); Dawn@4: set(handles.pushbutton_matfile_browse, 'Enable', 'Off'); Dawn@4: else Dawn@4: set(handles.edit_matdir, 'Enable', 'On'); Dawn@4: set(handles.pushbutton_matfile_browse, 'Enable', 'On'); Dawn@4: end Dawn@4: Dawn@4: if (VSData.vars.recursedir) Dawn@4: func_setlistbox(handles.listbox_wavfilelist, VSData.vars.MD_wavdir, 'recurse', VSData.vars, VSData.vars.I_searchstring); Dawn@4: else Dawn@4: func_setlistbox(handles.listbox_wavfilelist, VSData.vars.MD_wavdir, 'none', VSData.vars, VSData.vars.I_searchstring); Dawn@4: end Dawn@4: Dawn@4: set(handles.listbox_Data_paramlist, 'String', func_getmanualdataparameterlist()); Dawn@4: set(handles.edit_Data_invalid, 'String', VSData.vars.MD_invalidentry); Dawn@4: set(handles.checkbox_resample, 'Value', VSData.vars.MD_resample); Dawn@4: Dawn@4: % Update handles structure Dawn@4: guidata(hObject, handles); Dawn@4: Dawn@4: checkParameters(handles); Dawn@4: plotParam(handles); Dawn@4: Dawn@4: % UIWAIT makes vs_ManualData wait for user response (see UIRESUME) Dawn@4: % uiwait(handles.figure_ManualData); Dawn@4: Dawn@4: Dawn@4: % -- plot the current selected parameter Dawn@4: function plotParam(handles) Dawn@4: VSData = guidata(handles.VSHandle); Dawn@4: contents = get(handles.listbox_wavfilelist, 'String'); Dawn@4: OF = str2double(get(handles.edit_Data_offset, 'String')); Dawn@4: Dawn@4: if (isempty(contents)) Dawn@4: return; Dawn@4: end Dawn@4: Dawn@4: shortwavfile = contents{get(handles.listbox_wavfilelist, 'Value')}; Dawn@4: wavfile = [VSData.vars.MD_wavdir VSData.vars.dirdelimiter shortwavfile]; Dawn@4: Dawn@4: [y,Fs] = wavread(wavfile); Dawn@4: L = floor((length(y) / Fs * 1000) / VSData.vars.frameshift) - 1; Dawn@4: set(handles.edit_Data_explen, 'String', num2str(L)); Dawn@4: Dawn@4: % set the amount of padding needed Dawn@4: figdata = guidata(handles.figure_ManualData); Dawn@4: NL = str2double(get(handles.edit_Data_newlen, 'String')); Dawn@4: set(handles.edit_Data_pad, 'String', num2str(L - NL - OF)); Dawn@4: Dawn@4: Dawn@4: if (isfield(figdata, 'mdata')) Dawn@4: contents = get(handles.listbox_Data_paramlist, 'String'); Dawn@4: Dawn@4: if (isempty(contents)) Dawn@4: return; Dawn@4: end Dawn@4: Dawn@4: label = contents{get(handles.listbox_Data_paramlist, 'Value')}; Dawn@4: C = textscan(label, '%s %s', 'delimiter', '('); Dawn@4: param = C{2}{1}(1:end-1); Dawn@4: Dawn@4: % if the parameter exists, plot it in blue Dawn@4: if (isfield(figdata.mdata, param)) Dawn@4: plot(handles.axes_main, figdata.mdata.(param)); % plot the existing param Dawn@4: L = length(figdata.mdata.(param)); Dawn@4: set(handles.edit_Data_explen, 'String', num2str(L)); Dawn@4: set(handles.edit_Data_pad, 'String', num2str(L - NL - OF)); Dawn@4: axis(handles.axes_main, 'tight'); Dawn@4: else Dawn@4: cla(handles.axes_main); Dawn@4: end Dawn@4: end Dawn@4: Dawn@4: if (VSData.vars.MD_resample && isfield(figdata, 'newdata_resamp')) Dawn@4: hold(handles.axes_main, 'on'); Dawn@4: newdata = zeros(L, 1) * NaN; Dawn@4: if (OF >= 0) Dawn@4: newdata(OF+1:L) = figdata.newdata_resamp; Dawn@4: else Dawn@4: newdata(1:length(figdata.newdata_resamp) + OF) = figdata.newdata_resamp(abs(OF)+1:end); Dawn@4: end Dawn@4: plot(handles.axes_main, newdata, 'r'); Dawn@4: hold(handles.axes_main, 'off'); Dawn@4: axis(handles.axes_main, 'tight'); Dawn@4: hold(handles.axes_main, 'off'); Dawn@4: Dawn@4: elseif (isfield(figdata, 'newdata')) Dawn@4: hold(handles.axes_main, 'on'); Dawn@4: % create new vector Dawn@4: newdata = zeros(L, 1) * NaN; Dawn@4: if (length(figdata.newdata) + OF >= L) Dawn@4: newdata(OF+1:L) = figdata.newdata(1:L-OF); Dawn@4: else Dawn@4: if (OF >=0) Dawn@4: newdata(OF+1:OF+length(figdata.newdata)) = figdata.newdata; Dawn@4: else Dawn@4: newdata(1:length(figdata.newdata)+OF) = figdata.newdata(abs(OF)+1:end); Dawn@4: end Dawn@4: end Dawn@4: Dawn@4: plot(handles.axes_main, newdata, 'r'); Dawn@4: hold(handles.axes_main, 'off'); Dawn@4: axis(handles.axes_main, 'tight'); Dawn@4: %legend(handles.axes_main, {'Original', 'New'}); Dawn@4: end Dawn@4: Dawn@4: Dawn@4: % -- build up the matfile if it exists Dawn@4: function checkParameters(handles) Dawn@4: VSData = guidata(handles.VSHandle); Dawn@4: contents = get(handles.listbox_wavfilelist, 'String'); Dawn@4: Dawn@4: if (isempty(contents)) Dawn@4: return; Dawn@4: end Dawn@4: Dawn@4: shortwavfile = contents{get(handles.listbox_wavfilelist, 'Value')}; Dawn@4: matfile = [VSData.vars.MD_matdir VSData.vars.dirdelimiter, shortwavfile(1:end-3) 'mat']; Dawn@4: Dawn@4: if (exist(matfile, 'file') == 0) Dawn@4: mdata = []; Dawn@4: else Dawn@4: mdata = func_buildMData(matfile, VSData.vars.O_smoothwinsize); Dawn@4: end Dawn@4: Dawn@4: % store mdata so it can be accessed by plotData Dawn@4: figdata = guidata(handles.figure_ManualData); Dawn@4: figdata.mdata = mdata; Dawn@4: guidata(handles.figure_ManualData, figdata); Dawn@4: Dawn@4: Dawn@4: Dawn@4: % --- Outputs from this function are returned to the command line. Dawn@4: function varargout = vs_ManualData_OutputFcn(hObject, eventdata, handles) Dawn@4: % varargout cell array for returning output args (see VARARGOUT); Dawn@4: % hObject handle to figure Dawn@4: % eventdata reserved - to be defined in a future version of MATLAB Dawn@4: % handles structure with handles and user data (see GUIDATA) Dawn@4: Dawn@4: % Get default command line output from handles structure Dawn@4: varargout{1} = handles.output; Dawn@4: Dawn@4: Dawn@4: Dawn@4: function edit_wavdir_Callback(hObject, eventdata, handles) Dawn@4: % hObject handle to edit_wavdir (see GCBO) Dawn@4: % eventdata reserved - to be defined in a future version of MATLAB Dawn@4: % handles structure with handles and user data (see GUIDATA) Dawn@4: Dawn@4: new_dir = get(hObject, 'String'); Dawn@4: Dawn@4: VSData = guidata(handles.VSHandle); Dawn@4: Dawn@4: if (exist(new_dir, 'dir') == 7) Dawn@4: VSData = func_setwavdir('MD_wavdir', new_dir, VSData); Dawn@4: Dawn@4: if (VSData.vars.recursedir) Dawn@4: func_setlistbox(handles.listbox_wavfilelist, VSData.vars.MD_wavdir, 'recurse', VSData.vars, VSData.vars.I_searchstring); Dawn@4: else Dawn@4: func_setlistbox(handles.listbox_wavfilelist, VSData.vars.MD_wavdir, 'none', VSData.vars, VSData.vars.I_searchstring); Dawn@4: end Dawn@4: Dawn@4: if (VSData.vars.PE_savematwithwav) Dawn@4: set(handles.edit_matdir, 'String', new_dir); Dawn@4: VSData = func_setmatdir('MD_matdir', new_dir, VSData); Dawn@4: end Dawn@4: guidata(handles.VSHandle, VSData); Dawn@4: else Dawn@4: msgbox('Error: directory not found.', 'Error', 'error', 'modal'); Dawn@4: set(hObject, 'String', VSData.vars.MD_wavdir); Dawn@4: end Dawn@4: Dawn@4: % --- Executes during object creation, after setting all properties. Dawn@4: function edit_wavdir_CreateFcn(hObject, eventdata, handles) Dawn@4: % hObject handle to edit_wavdir (see GCBO) Dawn@4: % eventdata reserved - to be defined in a future version of MATLAB Dawn@4: % handles empty - handles not created until after all CreateFcns called Dawn@4: Dawn@4: % Hint: edit controls usually have a white background on Windows. Dawn@4: % See ISPC and COMPUTER. Dawn@4: if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) Dawn@4: set(hObject,'BackgroundColor','white'); Dawn@4: end Dawn@4: Dawn@4: Dawn@4: % --- Executes on button press in pushbutton_wavfile_browse. Dawn@4: function pushbutton_wavfile_browse_Callback(hObject, eventdata, handles) Dawn@4: % hObject handle to pushbutton_wavfile_browse (see GCBO) Dawn@4: % eventdata reserved - to be defined in a future version of MATLAB Dawn@4: % handles structure with handles and user data (see GUIDATA) Dawn@4: current_dir = get(handles.edit_wavdir, 'String'); Dawn@4: new_dir = uigetdir(current_dir); Dawn@4: Dawn@4: VSData = guidata(handles.VSHandle); Dawn@4: Dawn@4: if (ischar(new_dir)) Dawn@4: VSData = func_setwavdir('MD_wavdir', new_dir, VSData); Dawn@4: set(handles.edit_wavdir, 'String', new_dir); Dawn@4: Dawn@4: if (VSData.vars.recursedir) Dawn@4: func_setlistbox(handles.listbox_wavfilelist, VSData.vars.MD_wavdir, 'recurse', VSData.vars, VSData.vars.I_searchstring); Dawn@4: else Dawn@4: func_setlistbox(handles.listbox_wavfilelist, VSData.vars.MD_wavdir, 'none', VSData.vars, VSData.vars.I_searchstring); Dawn@4: end Dawn@4: Dawn@4: % assume that mat files are saved with wavs Dawn@4: if (VSData.vars.MD_matwithwav == 1) Dawn@4: set(handles.edit_matdir, 'String', new_dir); Dawn@4: VSData = func_setmatdir('MD_matdir', new_dir, VSData); Dawn@4: end Dawn@4: Dawn@4: guidata(handles.VSHandle, VSData); Dawn@4: Dawn@4: end Dawn@4: Dawn@4: checkParameters(handles); Dawn@4: plotParam(handles); Dawn@4: Dawn@4: Dawn@4: Dawn@4: % --- Executes on selection change in listbox_wavfilelist. Dawn@4: function listbox_wavfilelist_Callback(hObject, eventdata, handles) Dawn@4: % hObject handle to listbox_wavfilelist (see GCBO) Dawn@4: % eventdata reserved - to be defined in a future version of MATLAB Dawn@4: % handles structure with handles and user data (see GUIDATA) Dawn@4: Dawn@4: % Hints: contents = get(hObject,'String') returns listbox_wavfilelist contents as cell array Dawn@4: % contents{get(hObject,'Value')} returns selected item from listbox_wavfilelist Dawn@4: checkParameters(handles); Dawn@4: plotParam(handles); Dawn@4: Dawn@4: Dawn@4: % --- Executes during object creation, after setting all properties. Dawn@4: function listbox_wavfilelist_CreateFcn(hObject, eventdata, handles) Dawn@4: % hObject handle to listbox_wavfilelist (see GCBO) Dawn@4: % eventdata reserved - to be defined in a future version of MATLAB Dawn@4: % handles empty - handles not created until after all CreateFcns called Dawn@4: Dawn@4: % Hint: listbox controls usually have a white background on Windows. Dawn@4: % See ISPC and COMPUTER. Dawn@4: if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) Dawn@4: set(hObject,'BackgroundColor','white'); Dawn@4: end Dawn@4: Dawn@4: Dawn@4: % --- Executes on selection change in listbox_Data_paramlist. Dawn@4: function listbox_Data_paramlist_Callback(hObject, eventdata, handles) Dawn@4: % hObject handle to listbox_Data_paramlist (see GCBO) Dawn@4: % eventdata reserved - to be defined in a future version of MATLAB Dawn@4: % handles structure with handles and user data (see GUIDATA) Dawn@4: Dawn@4: % Hints: contents = get(hObject,'String') returns listbox_Data_paramlist contents as cell array Dawn@4: % contents{get(hObject,'Value')} returns selected item from listbox_Data_paramlist Dawn@4: %checkParameters(handles); Dawn@4: plotParam(handles); Dawn@4: Dawn@4: Dawn@4: % --- Executes during object creation, after setting all properties. Dawn@4: function listbox_Data_paramlist_CreateFcn(hObject, eventdata, handles) Dawn@4: % hObject handle to listbox_Data_paramlist (see GCBO) Dawn@4: % eventdata reserved - to be defined in a future version of MATLAB Dawn@4: % handles empty - handles not created until after all CreateFcns called Dawn@4: Dawn@4: % Hint: listbox controls usually have a white background on Windows. Dawn@4: % See ISPC and COMPUTER. Dawn@4: if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) Dawn@4: set(hObject,'BackgroundColor','white'); Dawn@4: end Dawn@4: Dawn@4: Dawn@4: Dawn@4: function edit_Data_datafile_Callback(hObject, eventdata, handles) Dawn@4: % hObject handle to edit_Data_datafile (see GCBO) Dawn@4: % eventdata reserved - to be defined in a future version of MATLAB Dawn@4: % handles structure with handles and user data (see GUIDATA) Dawn@4: VSData = guidata(handles.VSHandle); Dawn@4: L = str2double(get(handles.edit_Data_explen, 'String')); Dawn@4: OF = str2double(get(handles.edit_Data_offset, 'String')); Dawn@4: Dawn@4: filename = get(hObject, 'String'); Dawn@4: Dawn@4: if (exist(filename,'file') == 2) Dawn@4: % try to read in the file Dawn@4: fid = fopen(filename, 'rt'); Dawn@4: set(handles.edit_Data_datafile, 'String', [pathname filename]); Dawn@4: Dawn@4: if (fid == -1) Dawn@4: msgbox('Error: Unable to open data file', 'Error', 'error', 'modal'); Dawn@4: return; Dawn@4: end Dawn@4: Dawn@4: data = textscan(fid, '%s', 'delimiter', '\n'); Dawn@4: fclose(fid); Dawn@4: Dawn@4: % get the specified labels for invalid entry Dawn@4: delimiters = textscan(VSData.vars.MD_invalidentry, '%s', 'delimiter', ','); Dawn@4: Dawn@4: % now check each entry Dawn@4: data = data{1}; Dawn@4: newdata = zeros(length(data), 1) * NaN; Dawn@4: Dawn@4: for k=1:length(data) Dawn@4: switch(data{k}) Dawn@4: case delimiters Dawn@4: Dawn@4: otherwise Dawn@4: newdata(k) = str2double(data{k}); Dawn@4: end Dawn@4: end Dawn@4: Dawn@4: figdata = guidata(handles.figure_ManualData); Dawn@4: figdata.newdata = newdata; Dawn@4: Dawn@4: if (VSData.vars.MD_resample) Dawn@4: guidata(handles.figure_ManualData, figdata); Dawn@4: end Dawn@4: Dawn@4: guidata(handles.figure_ManualData, figdata); Dawn@4: Dawn@4: plotParam(handles); Dawn@4: Dawn@4: set(handles.edit_Data_newlen, 'String', num2str(length(newdata))); Dawn@4: set(handles.edit_Data_pad, 'String', num2str(L - OF - length(newdata))); Dawn@4: Dawn@4: end Dawn@4: Dawn@4: Dawn@4: % --- Executes during object creation, after setting all properties. Dawn@4: function edit_Data_datafile_CreateFcn(hObject, eventdata, handles) Dawn@4: % hObject handle to edit_Data_datafile (see GCBO) Dawn@4: % eventdata reserved - to be defined in a future version of MATLAB Dawn@4: % handles empty - handles not created until after all CreateFcns called Dawn@4: Dawn@4: % Hint: edit controls usually have a white background on Windows. Dawn@4: % See ISPC and COMPUTER. Dawn@4: if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) Dawn@4: set(hObject,'BackgroundColor','white'); Dawn@4: end Dawn@4: Dawn@4: Dawn@4: % --- Executes on button press in pushbutton_datafile_browse. Dawn@4: function pushbutton_datafile_browse_Callback(hObject, eventdata, handles) Dawn@4: % hObject handle to pushbutton_datafile_browse (see GCBO) Dawn@4: % eventdata reserved - to be defined in a future version of MATLAB Dawn@4: % handles structure with handles and user data (see GUIDATA) Dawn@4: Dawn@4: VSData = guidata(handles.VSHandle); Dawn@4: L = str2double(get(handles.edit_Data_explen, 'String')); Dawn@4: OF = str2double(get(handles.edit_Data_offset, 'String')); Dawn@4: current_dir = get(handles.edit_wavdir, 'String'); Dawn@4: Dawn@4: [filename, pathname] = uigetfile({'*.txt'; '*.*'}, 'Select data file', current_dir); Dawn@4: Dawn@4: if (filename ~= 0) Dawn@4: % try to read in the file Dawn@4: fid = fopen([pathname filename], 'rt'); Dawn@4: set(handles.edit_Data_datafile, 'String', [pathname filename]); Dawn@4: Dawn@4: if (fid == -1) Dawn@4: msgbox('Error: Unable to open data file', 'Error', 'error', 'modal'); Dawn@4: return; Dawn@4: end Dawn@4: Dawn@4: data = textscan(fid, '%s', 'delimiter', '\n'); Dawn@4: fclose(fid); Dawn@4: Dawn@4: % get the specified labels for invalid entry Dawn@4: delimiters = textscan(VSData.vars.MD_invalidentry, '%s', 'delimiter', ','); Dawn@4: Dawn@4: % now check each entry Dawn@4: data = data{1}; Dawn@4: newdata = zeros(length(data), 1) * NaN; Dawn@4: Dawn@4: for k=1:length(data) Dawn@4: switch(data{k}) Dawn@4: case delimiters Dawn@4: Dawn@4: otherwise Dawn@4: newdata(k) = str2double(data{k}); Dawn@4: end Dawn@4: end Dawn@4: Dawn@4: figdata = guidata(handles.figure_ManualData); Dawn@4: figdata.newdata = newdata; Dawn@4: Dawn@4: if (VSData.vars.MD_resample) Dawn@4: figdata = resample_signal(figdata, handles); Dawn@4: end Dawn@4: guidata(handles.figure_ManualData, figdata); Dawn@4: Dawn@4: plotParam(handles); Dawn@4: Dawn@4: set(handles.edit_Data_newlen, 'String', num2str(length(newdata))); Dawn@4: set(handles.edit_Data_pad, 'String', num2str(L - OF - length(newdata))); Dawn@4: Dawn@4: end Dawn@4: Dawn@4: Dawn@4: Dawn@4: function edit_Data_offset_Callback(hObject, eventdata, handles) Dawn@4: % hObject handle to edit_Data_offset (see GCBO) Dawn@4: % eventdata reserved - to be defined in a future version of MATLAB Dawn@4: % handles structure with handles and user data (see GUIDATA) Dawn@4: VSData = guidata(handles.VSHandle); Dawn@4: Dawn@4: str = get(hObject, 'String'); Dawn@4: num = str2double(str); Dawn@4: if (isnan(num)) Dawn@4: set(hObject, 'String', num2str(VSData.vars.MD_offset)); Dawn@4: else Dawn@4: VSData.vars.MD_offset = num; Dawn@4: guidata(handles.VSHandle, VSData); Dawn@4: Dawn@4: % update the other numbers Dawn@4: L = str2double(get(handles.edit_Data_explen, 'String')); Dawn@4: NDL = str2double(get(handles.edit_Data_newlen, 'String')); Dawn@4: set(handles.edit_Data_pad, 'String', num2str(L - num - NDL)); Dawn@4: Dawn@4: if (VSData.vars.MD_resample) Dawn@4: figdata = guidata(handles.figure_ManualData); Dawn@4: figdata = resample_signal(figdata, handles); Dawn@4: guidata(handles.figure_ManualData, figdata); Dawn@4: end Dawn@4: Dawn@4: plotParam(handles); Dawn@4: end Dawn@4: Dawn@4: % --- Executes during object creation, after setting all properties. Dawn@4: function edit_Data_offset_CreateFcn(hObject, eventdata, handles) Dawn@4: % hObject handle to edit_Data_offset (see GCBO) Dawn@4: % eventdata reserved - to be defined in a future version of MATLAB Dawn@4: % handles empty - handles not created until after all CreateFcns called Dawn@4: Dawn@4: % Hint: edit controls usually have a white background on Windows. Dawn@4: % See ISPC and COMPUTER. Dawn@4: if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) Dawn@4: set(hObject,'BackgroundColor','white'); Dawn@4: end Dawn@4: Dawn@4: Dawn@4: Dawn@4: function edit_matdir_Callback(hObject, eventdata, handles) Dawn@4: % hObject handle to edit_matdir (see GCBO) Dawn@4: % eventdata reserved - to be defined in a future version of MATLAB Dawn@4: % handles structure with handles and user data (see GUIDATA) Dawn@4: Dawn@4: new_dir = get(hObject, 'String'); Dawn@4: VSData = guidata(handles.VSHandle); Dawn@4: Dawn@4: if (exist(new_dir, 'dir') == 7) Dawn@4: VSData = func_setmatdir('MD_matdir', new_dir, VSData); Dawn@4: set(handles.edit_matdir, 'String', new_dir); Dawn@4: Dawn@4: guidata(handles.VSHandle, VSData); Dawn@4: else Dawn@4: msgbox('Error: directory not found.', 'Error', 'error', 'modal'); Dawn@4: set(hObject, 'String', VSData.vars.MD_matdir); Dawn@4: end Dawn@4: Dawn@4: Dawn@4: % --- Executes during object creation, after setting all properties. Dawn@4: function edit_matdir_CreateFcn(hObject, eventdata, handles) Dawn@4: % hObject handle to edit_matdir (see GCBO) Dawn@4: % eventdata reserved - to be defined in a future version of MATLAB Dawn@4: % handles empty - handles not created until after all CreateFcns called Dawn@4: Dawn@4: % Hint: edit controls usually have a white background on Windows. Dawn@4: % See ISPC and COMPUTER. Dawn@4: if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) Dawn@4: set(hObject,'BackgroundColor','white'); Dawn@4: end Dawn@4: Dawn@4: Dawn@4: % --- Executes on button press in pushbutton_matfile_browse. Dawn@4: function pushbutton_matfile_browse_Callback(hObject, eventdata, handles) Dawn@4: % hObject handle to pushbutton_matfile_browse (see GCBO) Dawn@4: % eventdata reserved - to be defined in a future version of MATLAB Dawn@4: % handles structure with handles and user data (see GUIDATA) Dawn@4: current_dir = get(handles.edit_matdir, 'String'); Dawn@4: new_dir = uigetdir(current_dir); Dawn@4: Dawn@4: VSData = guidata(handles.VSHandle); Dawn@4: Dawn@4: if (ischar(new_dir)) Dawn@4: VSData = func_setmatdir('MD_matdir', new_dir, VSData); Dawn@4: set(handles.edit_matdir, 'String', new_dir); Dawn@4: Dawn@4: guidata(handles.VSHandle, VSData); Dawn@4: end Dawn@4: Dawn@4: checkParameters(handles); Dawn@4: plotParam(handles); Dawn@4: Dawn@4: Dawn@4: % --- Executes on button press in pushbutton_Data_save. Dawn@4: function pushbutton_Data_save_Callback(hObject, eventdata, handles) Dawn@4: % hObject handle to pushbutton_Data_save (see GCBO) Dawn@4: % eventdata reserved - to be defined in a future version of MATLAB Dawn@4: % handles structure with handles and user data (see GUIDATA) Dawn@4: VSData = guidata(handles.VSHandle); Dawn@4: figdata = guidata(handles.figure_ManualData); Dawn@4: Dawn@4: L = str2double(get(handles.edit_Data_explen, 'String')); Dawn@4: OF = VSData.vars.MD_offset; Dawn@4: Dawn@4: % check we have something to save to Dawn@4: wavfilelist = get(handles.listbox_wavfilelist, 'String'); Dawn@4: if (isempty(wavfilelist)) Dawn@4: msgbox('Error: no wav files found.', 'Error', 'error', 'modal'); Dawn@4: return; Dawn@4: end Dawn@4: Dawn@4: paramlist = get(handles.listbox_Data_paramlist, 'String'); Dawn@4: if (isempty(paramlist)) Dawn@4: msgbox('Error: no parameters found.', 'Error', 'error', 'modal'); Dawn@4: return; Dawn@4: end Dawn@4: Dawn@4: % get the parameter Dawn@4: label = paramlist{get(handles.listbox_Data_paramlist, 'Value')}; Dawn@4: C = textscan(label, '%s %s', 'delimiter', '('); Dawn@4: param = C{2}{1}(1:end-1); Dawn@4: Dawn@4: shortwavfile = wavfilelist{get(handles.listbox_wavfilelist, 'Value')}; Dawn@4: matfile = [VSData.vars.MD_matdir VSData.vars.dirdelimiter shortwavfile(1:end-3) 'mat']; Dawn@4: Dawn@4: Dawn@4: if (VSData.vars.MD_resample && isfield(figdata, 'newdata_resamp')) Dawn@4: data = figdata.newdata_resamp; Dawn@4: elseif (~VSData.vars.MD_resample && isfield(figdata, 'newdata')) Dawn@4: data = figdata.newdata; Dawn@4: else Dawn@4: msgbox('Error: no new data loaded.', 'Error', 'error', 'modal'); Dawn@4: return; Dawn@4: end Dawn@4: Dawn@4: newdata = zeros(L, 1) * NaN; Dawn@4: if (length(data) + OF >= L) Dawn@4: newdata(OF+1:L) = data; Dawn@4: else Dawn@4: if (OF >= 0) Dawn@4: newdata(OF+1:OF+length(data)) = data; Dawn@4: else Dawn@4: newdata(1:length(data)+OF) = data(abs(OF)+1:end); Dawn@4: end Dawn@4: end Dawn@4: Dawn@4: Dawn@4: % create the new parameter here Dawn@4: eval([sprintf(param) '= newdata;']); Dawn@4: if (exist(matfile, 'file') == 2) % mat file already exist Dawn@4: save(matfile, param, '-append'); Dawn@4: else Dawn@4: save(matfile, param); Dawn@4: end Dawn@4: Dawn@4: msgbox('Save complete.', 'Save', 'help', 'modal'); Dawn@4: Dawn@4: Dawn@4: Dawn@4: Dawn@4: function edit_Data_explen_Callback(hObject, eventdata, handles) Dawn@4: % hObject handle to edit_Data_explen (see GCBO) Dawn@4: % eventdata reserved - to be defined in a future version of MATLAB Dawn@4: % handles structure with handles and user data (see GUIDATA) Dawn@4: Dawn@4: % Hints: get(hObject,'String') returns contents of edit_Data_explen as text Dawn@4: % str2double(get(hObject,'String')) returns contents of edit_Data_explen as a double Dawn@4: Dawn@4: Dawn@4: % --- Executes during object creation, after setting all properties. Dawn@4: function edit_Data_explen_CreateFcn(hObject, eventdata, handles) Dawn@4: % hObject handle to edit_Data_explen (see GCBO) Dawn@4: % eventdata reserved - to be defined in a future version of MATLAB Dawn@4: % handles empty - handles not created until after all CreateFcns called Dawn@4: Dawn@4: % Hint: edit controls usually have a white background on Windows. Dawn@4: % See ISPC and COMPUTER. Dawn@4: if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) Dawn@4: set(hObject,'BackgroundColor','white'); Dawn@4: end Dawn@4: Dawn@4: Dawn@4: Dawn@4: function edit_Data_pad_Callback(hObject, eventdata, handles) Dawn@4: % hObject handle to edit_Data_pad (see GCBO) Dawn@4: % eventdata reserved - to be defined in a future version of MATLAB Dawn@4: % handles structure with handles and user data (see GUIDATA) Dawn@4: Dawn@4: % Hints: get(hObject,'String') returns contents of edit_Data_pad as text Dawn@4: % str2double(get(hObject,'String')) returns contents of edit_Data_pad as a double Dawn@4: Dawn@4: Dawn@4: % --- Executes during object creation, after setting all properties. Dawn@4: function edit_Data_pad_CreateFcn(hObject, eventdata, handles) Dawn@4: % hObject handle to edit_Data_pad (see GCBO) Dawn@4: % eventdata reserved - to be defined in a future version of MATLAB Dawn@4: % handles empty - handles not created until after all CreateFcns called Dawn@4: Dawn@4: % Hint: edit controls usually have a white background on Windows. Dawn@4: % See ISPC and COMPUTER. Dawn@4: if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) Dawn@4: set(hObject,'BackgroundColor','white'); Dawn@4: end Dawn@4: Dawn@4: Dawn@4: Dawn@4: function edit_Data_newlen_Callback(hObject, eventdata, handles) Dawn@4: % hObject handle to edit_Data_newlen (see GCBO) Dawn@4: % eventdata reserved - to be defined in a future version of MATLAB Dawn@4: % handles structure with handles and user data (see GUIDATA) Dawn@4: Dawn@4: % Hints: get(hObject,'String') returns contents of edit_Data_newlen as text Dawn@4: % str2double(get(hObject,'String')) returns contents of edit_Data_newlen as a double Dawn@4: Dawn@4: Dawn@4: % --- Executes during object creation, after setting all properties. Dawn@4: function edit_Data_newlen_CreateFcn(hObject, eventdata, handles) Dawn@4: % hObject handle to edit_Data_newlen (see GCBO) Dawn@4: % eventdata reserved - to be defined in a future version of MATLAB Dawn@4: % handles empty - handles not created until after all CreateFcns called Dawn@4: Dawn@4: % Hint: edit controls usually have a white background on Windows. Dawn@4: % See ISPC and COMPUTER. Dawn@4: if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) Dawn@4: set(hObject,'BackgroundColor','white'); Dawn@4: end Dawn@4: Dawn@4: Dawn@4: Dawn@4: function edit_Data_invalid_Callback(hObject, eventdata, handles) Dawn@4: % hObject handle to edit_Data_invalid (see GCBO) Dawn@4: % eventdata reserved - to be defined in a future version of MATLAB Dawn@4: % handles structure with handles and user data (see GUIDATA) Dawn@4: Dawn@4: % Hints: get(hObject,'String') returns contents of edit_Data_invalid as text Dawn@4: % str2double(get(hObject,'String')) returns contents of edit_Data_invalid as a double Dawn@4: VSData = guidata(handles.VSHandle); Dawn@4: VSData.vars.MD_invalidentry = get(hObject, 'String'); Dawn@4: guidata(handles.VSHandle, VSData); Dawn@4: Dawn@4: Dawn@4: % --- Executes during object creation, after setting all properties. Dawn@4: function edit_Data_invalid_CreateFcn(hObject, eventdata, handles) Dawn@4: % hObject handle to edit_Data_invalid (see GCBO) Dawn@4: % eventdata reserved - to be defined in a future version of MATLAB Dawn@4: % handles empty - handles not created until after all CreateFcns called Dawn@4: Dawn@4: % Hint: edit controls usually have a white background on Windows. Dawn@4: % See ISPC and COMPUTER. Dawn@4: if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) Dawn@4: set(hObject,'BackgroundColor','white'); Dawn@4: end Dawn@4: Dawn@4: Dawn@4: Dawn@4: % --- Executes on button press in checkbox_resample. Dawn@4: function checkbox_resample_Callback(hObject, eventdata, handles) Dawn@4: % hObject handle to checkbox_resample (see GCBO) Dawn@4: % eventdata reserved - to be defined in a future version of MATLAB Dawn@4: % handles structure with handles and user data (see GUIDATA) Dawn@4: VSData = guidata(handles.VSHandle); Dawn@4: VSData.vars.MD_resample = get(hObject, 'Value'); Dawn@4: guidata(handles.VSHandle, VSData); Dawn@4: Dawn@4: if (VSData.vars.MD_resample) Dawn@4: figdata = guidata(handles.figure_ManualData); Dawn@4: figdata = resample_signal(figdata, handles); Dawn@4: guidata(handles.figure_ManualData, figdata); Dawn@4: end Dawn@4: Dawn@4: plotParam(handles); Dawn@4: Dawn@4: Dawn@4: Dawn@4: Dawn@4: % -- resample the signal if required Dawn@4: function figdata = resample_signal(figdata, handles) Dawn@4: VSData = guidata(handles.VSHandle); Dawn@4: Dawn@4: if (~isfield(figdata, 'newdata')) Dawn@4: return; Dawn@4: end Dawn@4: Dawn@4: newL = str2double(get(handles.edit_Data_explen, 'String')); Dawn@4: Dawn@4: if (length(figdata.newdata)==1) Dawn@4: figdata.newdata_resamp = ones(newL, 1) * figdata.newdata; Dawn@4: Dawn@4: else Dawn@4: try Dawn@4: figdata.newdata_resamp = resample(figdata.newdata, newL, length(figdata.newdata)); Dawn@4: catch ME Dawn@4: msgbox({'Error: Unable to run resample function.', '(Requires Signal Processing Toolbox)'}, 'Error', 'error', 'modal'); Dawn@4: end Dawn@4: end Dawn@4: Dawn@4: Dawn@4: % --- Executes on button press in checkbox_matwithwav. Dawn@4: function checkbox_matwithwav_Callback(hObject, eventdata, handles) Dawn@4: % hObject handle to checkbox_matwithwav (see GCBO) Dawn@4: % eventdata reserved - to be defined in a future version of MATLAB Dawn@4: % handles structure with handles and user data (see GUIDATA) Dawn@4: Dawn@4: VSData = guidata(handles.VSHandle); Dawn@4: VSData.vars.MD_matwithwav = get(hObject, 'Value'); Dawn@4: Dawn@4: if (VSData.vars.MD_matwithwav) Dawn@4: set(handles.edit_matdir, 'Enable', 'Off'); Dawn@4: set(handles.pushbutton_matfile_browse, 'Enable', 'Off'); Dawn@4: else Dawn@4: set(handles.edit_matdir, 'Enable', 'On'); Dawn@4: set(handles.pushbutton_matfile_browse, 'Enable', 'On'); Dawn@4: end Dawn@4: Dawn@4: guidata(handles.VSHandle, VSData);