Strange issue with mean, max, and min of vector?

2 ビュー (過去 30 日間)
FsC
FsC 2024 年 6 月 17 日
コメント済み: Star Strider 2024 年 6 月 18 日
Hello,
I am having an issue with finding the mean max and min of a vector (attached). All values in the vector are positive (increments of time) and less than 1. However, when I test the mean() = -8.0219, max = 9.5770, min = -4.3200e+04. When I try to find() the indices of the min and max, it says that it is 1 but, the value at index 1 is 0.012.
When you test the vector, do you get the same result? Why is it outputting these incorrect values?

採用された回答

Star Strider
Star Strider 2024 年 6 月 18 日
編集済み: Star Strider 2024 年 6 月 18 日
See the plotted values —
load('diffT.mat')
whos('-file','diffT')
Name Size Bytes Class Attributes diffT 5370x1 42960 double
% diffT
neg_vals = nnz(diffT < 0)
neg_vals = 1
[lo,hi] = bounds(diffT)
lo = -4.3200e+04
hi = 9.5770
diffT_median = median(diffT)
diffT_median = 0.0170
diffT_mean = mean(diffT)
diffT_mean = -8.0219
figure
plot(diffT)
grid
xlabel('Index')
ylabel('diffT (Everything)')
figure
plot(diffT)
grid
xlabel('Index')
ylabel('diffT (Bounded)')
ylim([min(diffT(1:1000)) max(diffT(1:2000))])
diffT_out = filloutliers(diffT,'nearest'); % Detect & Fill The Outlier
[lo,hi] = bounds(diffT_out)
lo = 0.0130
hi = 0.0210
median_diffT_out = median(diffT_out)
median_diffT_out = 0.0170
mean_diffT_out = mean(diffT_out)
mean_diffT_out = 0.0165
stdev_diffT_out = std(diffT_out)
stdev_diffT_out = 7.1457e-04
figure
plot(diffT_out)
grid
xlabel('Index')
ylabel('diffT\_out')
figure
histfit(diffT_out, 100, 'lognormal')
grid
Your statement ‘All values in the vector are positive’ seems not to be the actual situation. There is one value that is equal to -43200, and that sort of spoils the party. You might want to see how that large negative value managed to get in your ‘diffT’ data.
When in doubt, plot the data!
EDIT — Corrected typographical errors.
.
  2 件のコメント
FsC
FsC 2024 年 6 月 18 日
移動済み: Steven Lord 2024 年 6 月 18 日
Thank you for the thorough answer! Now I know to plot in the future
Star Strider
Star Strider 2024 年 6 月 18 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTime Series Events についてさらに検索

タグ

製品


リリース

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by