Norm and mean of a time series

8 views (last 30 days)
Haya Ali
Haya Ali on 18 May 2021
Edited: Scott MacKenzie on 26 May 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]
for i=1:length(x1)
for i=1:length(x1)
Error using norm
Not enough input arguments.
Error in DMN_ROI (line 27)
  1 Comment
Atsushi Ueno
Atsushi Ueno on 18 May 2021
Edited: Atsushi Ueno on 18 May 2021
The error occurs because you are using the variable "norm" before defining it.
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".

Sign in to comment.

Accepted Answer

Scott MacKenzie
Scott MacKenzie on 18 May 2021
Edited: Scott MacKenzie on 26 May 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
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

Sign in to comment.

More Answers (0)


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!