Matrix contains incorrect values if disp(matrix), but if disp(matrix (2,1)) it returns a correct value

1 view (last 30 days)
Hello everyone, I am a beginner with matlab and I would really appreaciate if somone would give me a bit of help, since i have quite poor knowledge of matlab. I have a vector of returns that has length of 4475. I want to create a moving window of 250 observations, so that for each pack of 250 observations I could use a function mle(data,'distribution','tLocationScale); to estimate distribution. But what is crucial for me is to extract vector of degrees of freedom. My code looks like this:
N = length(returns_sp500);
l = 250;
for t = 1:(N-1+1)
if t<=4226
estPara_sp500(t,:)=mle(returns_sp500(t:(t+l-1)), ...
'distribution','tlocationscale');
else
break
end
end
But when I try to diplay it it shows me a matrix with mostly zeros. However, if I display a particular element of matrix it looks perfectly fine.
column1 = estPara_sp500(:, 3);
disp(column1) % zeros
disp(column1(1)) % returns a correct value
If someone has a clue where is my error and how can I fix it, please help :)

Accepted Answer

Steven Lord
Steven Lord on 8 Oct 2015
My guess is that some of the elements in your matrix are much larger than others. If so, this is likely just a display format issue.
format short
x = [1e6, 1.25];
disp('Format short gives:')
disp(x)
format long
disp('Format long gives:')
disp(x)
format longg
disp('Format longg gives:')
disp(x)
Note that I displayed the same x vector three times, but the displays were quite different. Because 1.25 is so small relative to 1e6, the scaling in the scaled display format FORMAT SHORT had to be large enough to display 1e6 that it displayed 1.25 as 0. The display format FORMAT LONG did better for this example, but if you changed x to [1e10, 1.25e-8] you'd see the same behavior. When I let FORMAT choose fixed or floating point using the LONGG (note the double G) format it was able to choose the appropriate format for each element of x.
For more information on the display formats see the help for the FORMAT function.

More Answers (0)

Categories

Find more on Dates and Time in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!