Inf resulted when calculating mean
古いコメントを表示
I am calculating the mean pe each year from 1993-2021. I have rounded my data set, drdata, to the 2 decimal place. However, the stockpe resulted in Inf for every year. I don't understand why this happens. I have already rounded it.
%drdata column 2 is date
%drdata column 4 is the pe ratio data
[year,~,~] = datevec(728110)
%storing the years in y (months and dates are not necessary)
%dates are stored in the 2nd column
[y,~,~] = datevec(drdata(:,2));
%calculating mean stock return for each year, return is in the 7th column
unique(y)
mask = y >= 1993 & y <= 2021;
nnz(mask)
nnz(isnan(drdata(mask,4)))
for k=1993:2021
stockpe(k-1992) = round(mean(drdata(y==k,4)),2);
%1st element will correspond to 1993, 2nd - 1994 and so on
end
4 件のコメント
Walter Roberson
2022 年 7 月 30 日
unique(y)
nnz(mask)
nnz(isnan(drdata(mask,4)))
those three lines are debugging steps, not regular commands needed by working code. please tell us what the output was of those three lines.
You would get inf if no entries in y were in the range 1993 to 2021
King To Leung
2022 年 7 月 30 日
Walter Roberson
2022 年 7 月 31 日
temp = drdata(y==1993,4);
size(temp)
min(temp), max(temp)
Please show the output of these debugging commands
King To Leung
2022 年 7 月 31 日
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!