首页 \ 问答 \ Matlab Gui:如何在函数之间共享数据(Matlab Gui: how to share datas among functions)

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
更新时间:2022-08-19 20:08

最满意答案

你可以做:

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'])

相关问答

更多

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。