# Norm and mean of a time series

8 Ansichten (letzte 30 Tage)
Haya Ali am 18 Mai 2021
Bearbeitet: Scott MacKenzie am 26 Mai 2021
I am very new to matlab and have a time series x1 and this time series should have zero mean and unit norm. I have been provided with the formula given below to calculate norm and mean But when i run the program it gives me the error shown below. Please help me to resolve the problem.
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]
mean=mean(x1)
for i=1:length(x1)
x1(i)=(x1(i)-mean)/norm
end
norm=norm(x1)
for i=1:length(x1)
x1(i)=x1(i)/norm
end
%%%Error%%%%
Error using norm
Not enough input arguments.
Error in DMN_ROI (line 27)
x1(i)=(x1(i)-mean)/norm
##### 1 KommentarKeine anzeigenKeine ausblenden
Atsushi Ueno am 18 Mai 2021
Bearbeitet: Atsushi Ueno am 18 Mai 2021
The error occurs because you are using the variable "norm" before defining it.
x1(i)=(x1(i)-mean)/norm
In line 27, you may think you are using the variable "norm", but since the variable has not been defined yet in line 27, MATLAB is trying to determine that norm is the name of the function, resulting in the error "Not enough input arguments".

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Scott MacKenzie am 18 Mai 2021
Bearbeitet: Scott MacKenzie am 26 Mai 2021
The first error is in the 3rd line. norm is a built-in MATLAB function and requires at least one input argument.
The second "error" (actually a "mistake") is on the 5th line in how you use the norm function. You correctly use norm with an input argument, but then you assign the result of the function to a variable named norm. This is actually allowed, but you need to realize that norm has now changed to a variable and is no longer a function. This creates an unintended side effect that will surface as an error if you use norm as a function later in your code.
Note that you also make the same mistake on the 1st line in your use of the mean function. It did not generate a syntax error from MATLAB, becuase this is (as I said) actually allowed. But, it is surely not what you intended.
Here's your code with these issues corrected:
mx = mean(x1); % assign the computed mean to a variable named mx
for i=1:length(x1)
x1(i) = (x1(i)-mx) / norm(x1); % correct use of norm function and use of variable mx
end
nx = norm(x1); % assign the computed norm to a variable named nx
for i=1:length(x1)
x1(i) = x1(i) / nx; % use of variable nx
end
##### 3 Kommentare2 ältere Kommentare anzeigen2 ältere Kommentare ausblenden
Haya Ali am 18 Mai 2021
Thanks a lot !

Melden Sie sich an, um zu kommentieren.

### Kategorien

Find more on Mathematics 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!

Translated by