Mean and Norm of a time series.

6 ビュー (過去 30 日間)
Haya Ali
Haya Ali 2021 年 5 月 18 日
編集済み: Haya Ali 2021 年 5 月 26 日
I have calculated the mean and norm of a time series. But i am confused because the code gives different values when run in editor and command windows. Please help to resolve the issue
clear all; close all; clc;
x1=[11500.2 11477.9 11417.3 11426.4 11413 11382.9 11375.1 11347.9 11351.1 11329.3]
mx_1 = mean(x1); % assign the computed mean to a variable named mx
for i=1:length(x1)
x1(i) = (x1(i)-mx_1) / norm(x1); % correct use of norm function and use of variable mx
end
nx_1 = norm(x1); % assign the computed norm to a variable named nx
for i=1:length(x1)
x1(i) = x1(i)/nx_1; % use of variable nx
end
In editor it gives values as
mx_1 =
1.1390e+04
nx_1 =
0.0128
but when i write norm (x1) and mean (x1) in command windows it gives this
norm(x1)
ans =
1.0000
mean (x1)
ans =
-0.0041

採用された回答

Steven Lord
Steven Lord 2021 年 5 月 18 日
The x1 variable you use to calculate mx_1 and nx_1 is not the same x1 that you use in the Command Window.
x1 = 1:10
x1 = 1×10
1 2 3 4 5 6 7 8 9 10
m1 = mean(x1)
m1 = 5.5000
x1 = normalize(x1, 'zscore') % This changes x1 so
x1 = 1×10
-1.4863 -1.1560 -0.8257 -0.4954 -0.1651 0.1651 0.4954 0.8257 1.1560 1.4863
m2 = mean(x1) % this variable is not equal to m1
m2 = 0
  1 件のコメント
Haya Ali
Haya Ali 2021 年 5 月 19 日
Thanks a lot!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStatistics and Machine Learning Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by