I'm trying to create an histogram with a normal distribution fitting. I wrote the code but it keeps on saying: index exceeds matrix dimension. Here's the code:
sigma=handles.Ht(end);
figure(1)
x_min = min(handles.array);
x_max = max(handles.array);
x_full = linspace(x_min,x_max,100);
x_partial = x_full(x_full < L);
y_full = normpdf(x_full,mean(handles.array),sigma);
y_partial = normpdf(x_partial,mean(handles.array),sigma);
area(x_full,y_full,'FaceColor','b');
hold on;
area(x_partial,y_partial,'FaceColor','r');
grid on;
% Histogram data
[count,bins] = hist(handles.array,30);
% Scale bins
num_returns = numel(handles.array);
scale = (bins(2)-bins(1))*num_returns;
% Plot full data set
a = bar(bins,count/scale,'w');
set(get(a,'Children'),'FaceAlpha',0.8)
hold off;
title(['Best Normal Fit of Returns. Red Indicates Returns Below VaR: ',num2str(L)],'FontWeight','bold');
handles.matrici.Mdati=[handles.array, handles.Ht, handles.VaR_p];
guidata(handles.figure1, handles);
Matlab says the error is the "area" function but I don't understand why. Any Ideas?
Index exceeds matrix dimensions.
Error in area (line 98)
set(h(1),'RefreshMode','auto');
Error in Var_final>inv_quantile (line 643)
area(x_partial,y_partial,'FaceColor','r');
Error in Var_final>pushbutton_calcola_Callback (line 309)
inv_quantile(handles)
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in Var_final (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
@(hObject,eventdata)Var_final('pushbutton_calcola_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
area
earlier in the code?