www.gusucode.com > Matlab动力系统和时间序列分析工具箱 > Matlab动力系统和时间序列分析工具箱/lab432/gui/add_data.m
function varargout = add_data(varargin) % ADD_DATA add data to TS % last modified 28.08.07 % Last Modified by GUIDE v2.5 21-Aug-2003 13:24:29 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @add_data_OpeningFcn, ... 'gui_OutputFcn', @add_data_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 during object creation, after setting all properties. function operation_list_CreateFcn(hObject, eventdata, handles) % hObject handle to operation_list (see GCBO) % handles empty - handles not created until after all CreateFcns called % Hint: listbox controls usually have a white background on Windows. % See ISPC and COMPUTER. set(hObject,'String',[{' '};{'Delay'};{'1st derivative'};{'2nd derivative'};{'User defined expression'}]); if ispc set(hObject,'BackgroundColor','white'); else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor')); end % --- Executes on selection change in operation_list. function operation_list_Callback(hObject, eventdata, handles) % hObject handle to operation_list (see GCBO) % handles structure with handles and user data (see GUIDATA) % Hints: contents = get(hObject,'String') returns operation_list contents as cell array % contents{get(hObject,'Value')} returns selected item from operation_list if get(hObject,'value')==1 set(handles.compute_button,'enable','off'); else set(handles.compute_button,'enable','on'); end if get(hObject,'value')==5 %-User defined expr. set(handles.expr_edit,'enable','on'); else set(handles.expr_edit,'enable','off'); end % --- Executes during object creation, after setting all properties. function crd_list_CreateFcn(hObject, eventdata, handles) % hObject handle to crd_list (see GCBO) % handles empty - handles not created until after all CreateFcns called % Hint: listbox controls usually have a white background on Windows. % See ISPC and COMPUTER. global TS GSD_GLOBALS if GSD_GLOBALS.en_dis.datapresent set(hObject,'String',TS.name); end if ispc set(hObject,'BackgroundColor','white'); else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor')); end % --- Executes just before add_data is made visible. function add_data_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to add_data (see VARARGIN) % Choose default command line output for add_data handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes add_data wait for user response (see UIRESUME) % uiwait(handles.add_crd_fig); global GSD_GLOBALS GSD_GLOBALS.advanced_fig_handles=[GSD_GLOBALS.advanced_fig_handles hObject]; % --- Outputs from this function are returned to the command line. function varargout = add_data_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure if ~isempty(handles) varargout{1} = handles.output; end % --- Executes on selection change in crd_list. function crd_list_Callback(hObject, eventdata, handles) % hObject handle to crd_list (see GCBO) % handles structure with handles and user data (see GUIDATA) % Hints: contents = get(hObject,'String') returns crd_list contents as cell array % contents{get(hObject,'Value')} returns selected item from crd_list set(handles.operation_list,'value',1); set(handles.compute_button,'enable','off'); set(handles.expr_edit,'enable','off'); % --- Executes during object creation, after setting all properties. function expr_edit_CreateFcn(hObject, eventdata, handles) % hObject handle to expr_edit (see GCBO) % 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 set(hObject,'BackgroundColor','white'); else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor')); end function expr_edit_Callback(hObject, eventdata, handles) % hObject handle to expr_edit (see GCBO) % handles structure with handles and user data (see GUIDATA) % --- Executes on button press in Close_button. function Close_button_Callback(hObject, eventdata, handles) % hObject handle to Close_button (see GCBO) % handles structure with handles and user data (see GUIDATA) close(handles.add_crd_fig); % --- Executes on button press in compute_button. function compute_button_Callback(hObject, eventdata, handles) % hObject handle to compute_button (see GCBO) % handles structure with handles and user data (see GUIDATA) global TS GSD_GLOBALS crdNo=get(handles.crd_list,'value'); operationNo=get(handles.operation_list,'value'); if GSD_GLOBALS.en_dis.datapresent Data=TS.data(:,crdNo); DataName=TS.name{crdNo}; Time=TS.time; end state=0; switch operationNo case 2 % Delay if GSD_GLOBALS.en_dis.datapresent [new_data,new_time,state]=get_delayed_crd(Data,Time,DataName); new_data_name={['delayed_' DataName]}; else warndlg('No data for operation','Action cancelled'); return end case 3 % 1st derivative if GSD_GLOBALS.en_dis.datapresent [new_data,state]=get_derivative('poly^4',1,Time',Data,Time'); new_time=Time; new_data_name={['Der1_' DataName]}; else warndlg('No data for operation','Action cancelled'); return end case 4 % 2nd derivative if GSD_GLOBALS.en_dis.datapresent [new_data,state]=get_derivative('poly^4',2,Time',Data,Time'); new_time=Time; new_data_name={['Der2_' DataName]}; else warndlg('No data for operation','Action cancelled'); return end case 5 % user defined expression str=get(handles.expr_edit,'string'); if ~GSD_GLOBALS.en_dis.datapresent try new_data=evalin('caller',str); catch errordlg('An error occured during this operation. New data not created','Error'); return end [m n]=size(new_data); for i=1:n new_data_name(i)={['user_def_expr' num2str(i)]}; end new_time=1:m; state=1; h=findobj('tag','MainFig'); if ~isempty(h) set(h,'name',['Lab432 [generated data]']); end else try for i=1:length(TS.data(1,:)) assignin('caller',['x' num2str(i)],TS.data(:,i)); end assignin('caller','x',Data); new_data=evalin('caller',str); for i=1:length(TS.data(1,:)) evalin('caller',['clear x' num2str(i)]); end evalin('caller','clear x'); new_time=Time; S1=size(new_time); S2=size(new_data); if (S1(1)~=S2(1))|(S1(2)~=S2(2)) state=0; else state=1; end new_data_name={['ude_' DataName]}; catch state=0; end end end if state if GSD_GLOBALS.en_dis.datapresent time=TS.time; data=TS.data; while new_time(1)>time(1) time(1)=[]; data(1,:)=[]; end while new_time(end)<time(end) time(end)=[]; data(end,:)=[]; end while new_time(1)<time(1) new_time(1)=[]; new_data(1)=[]; end while new_time(end)>time(end) new_time(end)=[]; new_data(end)=[]; end TS.data=data; TS.time=time; %%%%%%%%%%%%%%%%%% new_data=new_data(:); TS.data=[TS.data new_data]; k=length(TS.name); for i=1:length(new_data(1,:)) TS.name{k+i}=new_data_name{i}; end else new_data=new_data(:); new_time=new_time(:); TS.data=new_data; TS.time=new_time; TS.name=new_data_name; % TS=ts(new_data,new_data_name{1},new_time); GSD_GLOBALS.en_dis.datapresent=1; gui_en_dis; end set(handles.crd_list,'String',TS.name); set(hObject,'enable','off'); set(handles.operation_list,'value',1); set(handles.expr_edit,'enable','off'); else errordlg('An error occured during this operation. New data not created','Error'); end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function [new_data,new_time, state]=get_delayed_crd(Data,Time,DataName) state=0; new_data=[]; new_time=[]; prompt = {['Enter the time delay for ' DataName ':']}; dlg_title = 'Delaying'; num_lines= 1; def = {'1'}; answer = inputdlg(prompt,dlg_title,num_lines,def); if ~isempty(answer) delay=str2num(answer{1}); ix=min(find((Time-Time(1))>=delay)); new_time=Time(1:end-ix+1); % (ix:end); new_data=Data(ix:end); % %(1:end-ix+1); state=1; end