Matlab Gui:如何在函数之间共享数据(Matlab Gui: how to share datas among functions)
我是这个论坛和matlab GUI的新手。 我有这个问题。 我想创建一个GUI,允许您从xlsx文件加载数据,然后我想用这些数据计算GARCH模型。 我遇到的问题是我不知道如何将这些数据传递给函数GARCH。
这些是我写的功能。 希望您能够帮助我。
function open(handles) [FileName, PathName] = uigetfile('*.xlsx', 'Seleziona File dei Rendimenti'); A = xlsread(FileName, -1); inVdati = A(:); plot(inVdati, 'r'); legend('returns'); set(handles.Variance, 'Enable', 'on'); guidata(handles.figure1, handles) %saving values and function garch(handles) handles = guidata(handles.figure1); Sigmas = []; spec = garchset('P', 1, 'Q', 1); [Coeff, Errors, LLF, Innovations, Sigmas] = garchfit(spec, handles);
谁能告诉我我哪里错了?
谢谢你 :)
这是您需要的整个代码:
function varargout = Var_final(varargin) % VAR_FINAL MATLAB code for Var_final.fig % VAR_FINAL, by itself, creates a new VAR_FINAL or raises the existing % singleton*. % % H = VAR_FINAL returns the handle to a new VAR_FINAL or the handle to % the existing singleton*. % % VAR_FINAL('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in VAR_FINAL.M with the given input arguments. % % VAR_FINAL('Property','Value',...) creates a new VAR_FINAL or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before Var_final_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to Var_final_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 Var_final % Last Modified by GUIDE v2.5 18-Jan-2014 22:34:22 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @Var_final_OpeningFcn, ... 'gui_OutputFcn', @Var_final_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 Var_final is made visible. function Var_final_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 Var_final (see VARARGIN) % Choose default command line output for Var_final handles.figure1 = hObject; % Update handles structure guidata(hObject, handles); handles.inVdati = []; initialize_gui(handles); % UIWAIT makes Var_final wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = Var_final_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.figure1; function edit1_Callback(hObject, eventdata, handles) % hObject handle to edit1 (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 edit1 as text % str2double(get(hObject,'String')) returns contents of edit1 as a double % --- Executes during object creation, after setting all properties. function edit1_CreateFcn(hObject, eventdata, handles) % hObject handle to edit1 (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 listbox1. function listbox1_Callback(hObject, eventdata, handles) % hObject handle to listbox1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = cellstr(get(hObject,'String')) returns listbox1 contents as cell array % contents{get(hObject,'Value')} returns selected item from listbox1 % --- Executes during object creation, after setting all properties. function listbox1_CreateFcn(hObject, eventdata, handles) % hObject handle to listbox1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: listbox controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on selection change in listbox2. function listbox2_Callback(hObject, eventdata, handles) % hObject handle to listbox2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = cellstr(get(hObject,'String')) returns listbox2 contents as cell array % contents{get(hObject,'Value')} returns selected item from listbox2 % --- Executes during object creation, after setting all properties. function listbox2_CreateFcn(hObject, eventdata, handles) % hObject handle to listbox2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: listbox controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function edit2_Callback(hObject, eventdata, handles) % hObject handle to edit2 (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 edit2 as text % str2double(get(hObject,'String')) returns contents of edit2 as a double % --- Executes during object creation, after setting all properties. function edit2_CreateFcn(hObject, eventdata, handles) % hObject handle to edit2 (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 edit4_Callback(hObject, eventdata, handles) % hObject handle to edit4 (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 edit4 as text % str2double(get(hObject,'String')) returns contents of edit4 as a double % --- Executes during object creation, after setting all properties. function edit4_CreateFcn(hObject, eventdata, handles) % hObject handle to edit4 (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 popupmenu1. function popupmenu1_Callback(hObject, eventdata, handles) % hObject handle to popupmenu1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = cellstr(get(hObject,'String')) returns popupmenu1 contents as cell array % contents{get(hObject,'Value')} returns selected item from popupmenu1 % --- Executes during object creation, after setting all properties. function popupmenu1_CreateFcn(hObject, eventdata, handles) % hObject handle to popupmenu1 (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 popupmenu2. function popupmenu2_Callback(hObject, eventdata, handles) % hObject handle to popupmenu2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = cellstr(get(hObject,'String')) returns popupmenu2 contents as cell array % contents{get(hObject,'Value')} returns selected item from popupmenu2 handles.dati.strutt = get(hObject, 'Value'); % --- Executes during object creation, after setting all properties. function popupmenu2_CreateFcn(hObject, eventdata, handles) % hObject handle to popupmenu2 (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 radiobutton1. function radiobutton1_Callback(hObject, eventdata, handles) % hObject handle to radiobutton1 (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 radiobutton1 % --- Executes on button press in radiobutton2. function radiobutton2_Callback(hObject, eventdata, handles) % hObject handle to radiobutton2 (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 radiobutton2 % --- Executes on button press in radiobutton3. function radiobutton3_Callback(hObject, eventdata, handles) % hObject handle to radiobutton3 (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 radiobutton3 function edit7_Callback(hObject, eventdata, handles) % hObject handle to edit7 (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 edit7 as text % str2double(get(hObject,'String')) returns contents of edit7 as a double % --- Executes during object creation, after setting all properties. function edit7_CreateFcn(hObject, eventdata, handles) % hObject handle to edit7 (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 pushbutton_calcola. function pushbutton_calcola_Callback(hObject, eventdata, handles) % hObject handle to pushbutton_calcola (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) calcola(handles) % --- Executes on button press in pushbutton_reset. function pushbutton_reset_Callback(hObject, eventdata, handles) % hObject handle to pushbutton_reset (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) set(handles.edit4, 'value', 0) % -------------------------------------------------------------------- function M_File_Callback(hObject, eventdata, handles) % hObject handle to M_File (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function AA_File_Callback(hObject, eventdata, handles) % hObject handle to AA_File (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function A_File_Callback(hObject, eventdata, handles) % hObject handle to A_File (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) open(handles) % -------------------------------------------------------------------- function TB_Reset_ClickedCallback(hObject, eventdata, handles) % hObject handle to TB_Reset (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) gcbo(handles.figure1,handles) % -------------------------------------------------------------------- function TB_Salva_ClickedCallback(hObject, eventdata, handles) % hObject handle to TB_Salva (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) save_output(handles) % -------------------------------------------------------------------- function TB_Apri_ClickedCallback(hObject, eventdata, handles) % hObject handle to TB_Apri (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) open(handles) function initialize_gui(handles) %questa funzione serve a definire i valori iniziali della GUI e quando %viene premuto il pulsante reset %struttura dati handles.inputs.w=0; handles.inputs.V_0=0; handles.inputs.dist=0; handles.inputs.alpha=0; handles.dati.strutt=1; handles.dati.strutt1=1; handles.inputs.returns=0; %struttura vettori delle funzioni risolutrici handles.vettori.returns=[]; handles.vettori.sigmas=[]; handles.vettori.coeff=[]; handles.vettori.errors=[]; handles.vettori.LLF=[]; handles.vettori.Innovations=[]; handles.vettori.VAR=[]; %salvo le strutture create guidata(handles.figure1, handles); %passiamo i dati edit_text set(handles.popupmenu1, 'Value', 1); set(handles.popupmenu2, 'Value', 1); set(handles.edit4, 'String', handles.inputs.V_0); %nascondo assi all'apertura della GUI set(handles.axes1, 'Visible', 'off'); set(handles.axes2, 'Visible', 'off'); set(handles.Variance, 'Enable', 'off'); cla; %For Saving Outputs function save_output(handles) [Filename, Pathname] = uiputfile('.bmp', 'Save As'); Name = fullfile(Filename, Pathname); imwrite(img, Filename, 'bmp'); [Filename, Pathname] = uiputfile('*.bmp', 'Save As'); if Pathname==0, return; end function garch(handles) handles = guidata(handles.figure1, inVdati); Sigmas = []; spec = garchset('P', 1, 'Q', 1); [Coeff, Errors, LLF, Innovations, Sigmas] = garchfit(spec, handles); plot(Sigmas); % -------------------------------------------------------------------- function E_File_Callback(hObject, eventdata, handles) % hObject handle to E_File (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function Untitled_1_Callback(hObject, eventdata, handles) % hObject handle to Untitled_1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function R_File_Callback(hObject, eventdata, handles) % hObject handle to R_File (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) initialize_gui(handles) %caricare i rendimenti function open(handles) [FileName, PathName] = uigetfile('*.xlsx', 'Seleziona File dei Rendimenti'); A = xlsread(FileName, -1); inVdati = A(:); plot(inVdati, 'r'); legend('returns'); set(handles.Variance, 'Enable', 'on'); guidata(handles.figure1, inVdati) %saving values % --- Executes on button press in Variance. function Variance_Callback(hObject, eventdata, handles) % hObject handle to Variance (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) garch(handles) function tabella_dati(handles) inVdati = guidata(gcbo); %figura principale form1=figure('Position', [400,300,600,400], 'Name', 'Tabella Dati', ... 'NumberTitle', 'off', 'Color', [0.941 0.941 0.941], ... 'Resize', 'off', 'WindowStyle', 'normal'); %statit text testo = uicontrol(form1, 'Style', 'text', 'Position', [250, 370, 100, 25], ... 'String', 'Dati Numerici'); %Table cnames = {'Returns', 'Sigmas', 'Correlation', 'VaR'}; table = uitable('Data', 'inVdati', 'ColumnName', cnames,... 'Parent', form1, 'Position', [10 50 580 320]); %Pulsanti Esporta_Excel = uicontrol(form1, 'Style', 'pushbutton',... 'Position', [20, 10, 70, 25], 'String', 'Esporta in Excel', ... 'Callback', @esporta_excel_plot); Esporta_txt = uicontrol(form1, 'Style', 'pushbutton', ... 'Position', [110, 10, 70, 25], ... 'String', 'Esporta txt', 'Callback', @esporta_txt_plot); chiudi = uicontrol(form1, 'Style', 'pushbutton', 'Position', [200, 10, 70, 25], ... 'String', 'Chiudi', 'Callback', @chiudi_plot); % --- Executes on button press in parametric. function parametric_Callback(hObject, eventdata, handles) % hObject handle to parametric (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 parametric % --- Executes on button press in pushbutton5. function pushbutton5_Callback(hObject, eventdata, handles) % hObject handle to pushbutton5 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) axes(handles.axes1); plot(guidata(gcbo)); axes(handles.axes2); plot(Sigmas); % --- Executes on button press in pushbutton6. function pushbutton6_Callback(hObject, eventdata, handles) % hObject handle to pushbutton6 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) tabella_dati(handles)
I'm new to this forum and to matlab GUIs. I have this problem. I wanted to create a GUI which allows you to load data from an xlsx file and then I'd like to compute a GARCH model with this data. The problem I have is that I don't know how to pass this data to the function GARCH.
These are the functions I wrote. Hope you can help me.
function open(handles) [FileName, PathName] = uigetfile('*.xlsx', 'Seleziona File dei Rendimenti'); A = xlsread(FileName, -1); inVdati = A(:); plot(inVdati, 'r'); legend('returns'); set(handles.Variance, 'Enable', 'on'); guidata(handles.figure1, handles) %saving values and function garch(handles) handles = guidata(handles.figure1); Sigmas = []; spec = garchset('P', 1, 'Q', 1); [Coeff, Errors, LLF, Innovations, Sigmas] = garchfit(spec, handles);
Can anyone of you tell me where I'm wrong?
Thank u :)
This is the whole code in case you need it:
function varargout = Var_final(varargin) % VAR_FINAL MATLAB code for Var_final.fig % VAR_FINAL, by itself, creates a new VAR_FINAL or raises the existing % singleton*. % % H = VAR_FINAL returns the handle to a new VAR_FINAL or the handle to % the existing singleton*. % % VAR_FINAL('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in VAR_FINAL.M with the given input arguments. % % VAR_FINAL('Property','Value',...) creates a new VAR_FINAL or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before Var_final_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to Var_final_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 Var_final % Last Modified by GUIDE v2.5 18-Jan-2014 22:34:22 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @Var_final_OpeningFcn, ... 'gui_OutputFcn', @Var_final_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 Var_final is made visible. function Var_final_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 Var_final (see VARARGIN) % Choose default command line output for Var_final handles.figure1 = hObject; % Update handles structure guidata(hObject, handles); handles.inVdati = []; initialize_gui(handles); % UIWAIT makes Var_final wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = Var_final_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.figure1; function edit1_Callback(hObject, eventdata, handles) % hObject handle to edit1 (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 edit1 as text % str2double(get(hObject,'String')) returns contents of edit1 as a double % --- Executes during object creation, after setting all properties. function edit1_CreateFcn(hObject, eventdata, handles) % hObject handle to edit1 (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 listbox1. function listbox1_Callback(hObject, eventdata, handles) % hObject handle to listbox1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = cellstr(get(hObject,'String')) returns listbox1 contents as cell array % contents{get(hObject,'Value')} returns selected item from listbox1 % --- Executes during object creation, after setting all properties. function listbox1_CreateFcn(hObject, eventdata, handles) % hObject handle to listbox1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: listbox controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on selection change in listbox2. function listbox2_Callback(hObject, eventdata, handles) % hObject handle to listbox2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = cellstr(get(hObject,'String')) returns listbox2 contents as cell array % contents{get(hObject,'Value')} returns selected item from listbox2 % --- Executes during object creation, after setting all properties. function listbox2_CreateFcn(hObject, eventdata, handles) % hObject handle to listbox2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: listbox controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function edit2_Callback(hObject, eventdata, handles) % hObject handle to edit2 (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 edit2 as text % str2double(get(hObject,'String')) returns contents of edit2 as a double % --- Executes during object creation, after setting all properties. function edit2_CreateFcn(hObject, eventdata, handles) % hObject handle to edit2 (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 edit4_Callback(hObject, eventdata, handles) % hObject handle to edit4 (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 edit4 as text % str2double(get(hObject,'String')) returns contents of edit4 as a double % --- Executes during object creation, after setting all properties. function edit4_CreateFcn(hObject, eventdata, handles) % hObject handle to edit4 (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 popupmenu1. function popupmenu1_Callback(hObject, eventdata, handles) % hObject handle to popupmenu1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = cellstr(get(hObject,'String')) returns popupmenu1 contents as cell array % contents{get(hObject,'Value')} returns selected item from popupmenu1 % --- Executes during object creation, after setting all properties. function popupmenu1_CreateFcn(hObject, eventdata, handles) % hObject handle to popupmenu1 (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 popupmenu2. function popupmenu2_Callback(hObject, eventdata, handles) % hObject handle to popupmenu2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = cellstr(get(hObject,'String')) returns popupmenu2 contents as cell array % contents{get(hObject,'Value')} returns selected item from popupmenu2 handles.dati.strutt = get(hObject, 'Value'); % --- Executes during object creation, after setting all properties. function popupmenu2_CreateFcn(hObject, eventdata, handles) % hObject handle to popupmenu2 (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 radiobutton1. function radiobutton1_Callback(hObject, eventdata, handles) % hObject handle to radiobutton1 (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 radiobutton1 % --- Executes on button press in radiobutton2. function radiobutton2_Callback(hObject, eventdata, handles) % hObject handle to radiobutton2 (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 radiobutton2 % --- Executes on button press in radiobutton3. function radiobutton3_Callback(hObject, eventdata, handles) % hObject handle to radiobutton3 (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 radiobutton3 function edit7_Callback(hObject, eventdata, handles) % hObject handle to edit7 (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 edit7 as text % str2double(get(hObject,'String')) returns contents of edit7 as a double % --- Executes during object creation, after setting all properties. function edit7_CreateFcn(hObject, eventdata, handles) % hObject handle to edit7 (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 pushbutton_calcola. function pushbutton_calcola_Callback(hObject, eventdata, handles) % hObject handle to pushbutton_calcola (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) calcola(handles) % --- Executes on button press in pushbutton_reset. function pushbutton_reset_Callback(hObject, eventdata, handles) % hObject handle to pushbutton_reset (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) set(handles.edit4, 'value', 0) % -------------------------------------------------------------------- function M_File_Callback(hObject, eventdata, handles) % hObject handle to M_File (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function AA_File_Callback(hObject, eventdata, handles) % hObject handle to AA_File (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function A_File_Callback(hObject, eventdata, handles) % hObject handle to A_File (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) open(handles) % -------------------------------------------------------------------- function TB_Reset_ClickedCallback(hObject, eventdata, handles) % hObject handle to TB_Reset (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) gcbo(handles.figure1,handles) % -------------------------------------------------------------------- function TB_Salva_ClickedCallback(hObject, eventdata, handles) % hObject handle to TB_Salva (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) save_output(handles) % -------------------------------------------------------------------- function TB_Apri_ClickedCallback(hObject, eventdata, handles) % hObject handle to TB_Apri (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) open(handles) function initialize_gui(handles) %questa funzione serve a definire i valori iniziali della GUI e quando %viene premuto il pulsante reset %struttura dati handles.inputs.w=0; handles.inputs.V_0=0; handles.inputs.dist=0; handles.inputs.alpha=0; handles.dati.strutt=1; handles.dati.strutt1=1; handles.inputs.returns=0; %struttura vettori delle funzioni risolutrici handles.vettori.returns=[]; handles.vettori.sigmas=[]; handles.vettori.coeff=[]; handles.vettori.errors=[]; handles.vettori.LLF=[]; handles.vettori.Innovations=[]; handles.vettori.VAR=[]; %salvo le strutture create guidata(handles.figure1, handles); %passiamo i dati edit_text set(handles.popupmenu1, 'Value', 1); set(handles.popupmenu2, 'Value', 1); set(handles.edit4, 'String', handles.inputs.V_0); %nascondo assi all'apertura della GUI set(handles.axes1, 'Visible', 'off'); set(handles.axes2, 'Visible', 'off'); set(handles.Variance, 'Enable', 'off'); cla; %For Saving Outputs function save_output(handles) [Filename, Pathname] = uiputfile('.bmp', 'Save As'); Name = fullfile(Filename, Pathname); imwrite(img, Filename, 'bmp'); [Filename, Pathname] = uiputfile('*.bmp', 'Save As'); if Pathname==0, return; end function garch(handles) handles = guidata(handles.figure1, inVdati); Sigmas = []; spec = garchset('P', 1, 'Q', 1); [Coeff, Errors, LLF, Innovations, Sigmas] = garchfit(spec, handles); plot(Sigmas); % -------------------------------------------------------------------- function E_File_Callback(hObject, eventdata, handles) % hObject handle to E_File (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function Untitled_1_Callback(hObject, eventdata, handles) % hObject handle to Untitled_1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function R_File_Callback(hObject, eventdata, handles) % hObject handle to R_File (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) initialize_gui(handles) %caricare i rendimenti function open(handles) [FileName, PathName] = uigetfile('*.xlsx', 'Seleziona File dei Rendimenti'); A = xlsread(FileName, -1); inVdati = A(:); plot(inVdati, 'r'); legend('returns'); set(handles.Variance, 'Enable', 'on'); guidata(handles.figure1, inVdati) %saving values % --- Executes on button press in Variance. function Variance_Callback(hObject, eventdata, handles) % hObject handle to Variance (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) garch(handles) function tabella_dati(handles) inVdati = guidata(gcbo); %figura principale form1=figure('Position', [400,300,600,400], 'Name', 'Tabella Dati', ... 'NumberTitle', 'off', 'Color', [0.941 0.941 0.941], ... 'Resize', 'off', 'WindowStyle', 'normal'); %statit text testo = uicontrol(form1, 'Style', 'text', 'Position', [250, 370, 100, 25], ... 'String', 'Dati Numerici'); %Table cnames = {'Returns', 'Sigmas', 'Correlation', 'VaR'}; table = uitable('Data', 'inVdati', 'ColumnName', cnames,... 'Parent', form1, 'Position', [10 50 580 320]); %Pulsanti Esporta_Excel = uicontrol(form1, 'Style', 'pushbutton',... 'Position', [20, 10, 70, 25], 'String', 'Esporta in Excel', ... 'Callback', @esporta_excel_plot); Esporta_txt = uicontrol(form1, 'Style', 'pushbutton', ... 'Position', [110, 10, 70, 25], ... 'String', 'Esporta txt', 'Callback', @esporta_txt_plot); chiudi = uicontrol(form1, 'Style', 'pushbutton', 'Position', [200, 10, 70, 25], ... 'String', 'Chiudi', 'Callback', @chiudi_plot); % --- Executes on button press in parametric. function parametric_Callback(hObject, eventdata, handles) % hObject handle to parametric (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 parametric % --- Executes on button press in pushbutton5. function pushbutton5_Callback(hObject, eventdata, handles) % hObject handle to pushbutton5 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) axes(handles.axes1); plot(guidata(gcbo)); axes(handles.axes2); plot(Sigmas); % --- Executes on button press in pushbutton6. function pushbutton6_Callback(hObject, eventdata, handles) % hObject handle to pushbutton6 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) tabella_dati(handles)
原文:https://stackoverflow.com/questions/21216029
最满意答案
你可以做:
s = sum(X[k] for k in ['a','b','c','d'])
You can do:
s = sum(X[k] for k in ['a','b','c','d'])
相关问答
更多-
TCP/IP模型是一个________。[2023-05-19]
a -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
如果我理解正确,那就简单了: l_current = [{'type': 'food', 'drink': 'water'},{'type': 'food', 'drink': 'other'}] l_new = [{'type': 'food', 'drink': 'other'}, {'type': 'food', 'drink': 'dirt'}, {'type': 'food', 'drink': 'gasoline'}] l_final = [x for x ...
-
Pythonic方法确保列表在附加之前存在于dict键(Pythonic way to make sure list exists at dict key before appending)[2022-02-14]
pythonic方式是您已经发现的后者: defaultdict是一个dict子类,它调用工厂函数来提供缺失值。 它在python 2.5及更高版本中可用。 >>> import collections >>> d = collections.defaultdict(list) >>> d[0].append('potato') >>> d defaultdict(, {0: ['potato']}) 它的存在就是为了这个目的,所以尽可能避免使用dict.setdefault h ... -
pythonic从nest字典中调用特定键/值的方法(pythonic way of calling specific keys/values from a nest dictionary)[2024-01-27]
使用dict理解这是非常直接的: 码: new_dict = {k: v for k, v in nested_dict.items() if v['type'] % 2 != 0} 测试代码: nested_dict = {'bulldog': {'type': 3}, 'cat': {'type': 4}, 'yorkie': {'type': 11}, 'pitbull': {'type': 8}} new_dict = {k: v for k, v in neste ... -
Pythonic方法迭代字典中的列表并行作为一个字典(Pythonic way to iterate over lists inside a dict in parallel AS a dict)[2023-08-08]
您可以直接使用带有dict.values zip 例如: packed = { 'names': ['a', 'b', 'c', 'd'], 'values': ['A', 'B', 'C', 'D'] } keysValue = packed.keys() for pack in zip(*packed.values()): print( dict(zip(keysValue, pack)) ) 输出: {'values': 'A', 'names': 'a'} {'valu ... -
广泛使用生成器和列表理解,你可以像这样写: other = ['Other', 'Unknown'] # Strings denoting non-contries ids = set(i for i,j in mylist) # All ids in the list known = set(i for i,j in mylist if j not in other) # Ids of real countries ...
-
用特定键列表来总结字典值的pythonic方法?(A pythonic way to sum the values of a dict with a specified key list?)[2022-02-15]
你可以做: s = sum(X[k] for k in ['a','b','c','d']) You can do: s = sum(X[k] for k in ['a','b','c','d']) -
你可以使用词典理解: my_dict = {1: [2,3], 2: [4, 5], 3: [6, 7]} new_d = {a:sum(b) for a, b in my_dict.items()} 输出: {1: 5, 2: 9, 3: 13} You can use a dictionary comprehension: my_dict = {1: [2,3], 2: [4, 5], 3: [6, 7]} new_d = {a:sum(b) for a, b in my_dict.items()} ...
-
你总是可以做类似子类dict事情。 这是完全未经测试的,但有一些影响: class NoisyDict(dict): def __init__(self, *args, **kwargs): self.handlers = {} #Python 3 style super().__init__(*args, **kwargs) def add_handler(self, key, callback): self.handler ...