Norm and mean of a time series

11 visualizzazioni (ultimi 30 giorni)
Haya Ali
Haya Ali il 18 Mag 2021
Modificato: Scott MacKenzie il 26 Mag 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 Commento
Atsushi Ueno
Atsushi Ueno il 18 Mag 2021
Modificato: Atsushi Ueno il 18 Mag 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".

Accedi per commentare.

Risposta accettata

Scott MacKenzie
Scott MacKenzie il 18 Mag 2021
Modificato: Scott MacKenzie il 26 Mag 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 Commenti
Scott MacKenzie
Scott MacKenzie il 18 Mag 2021
The simplest way to see the values is to remove semi-colons at the end of lines. For example, change
mx = mean(x1);
to
mx = mean(x1)
When you run the scipt, the value is computed and sent to the Command Window.
You can get a bit fancy and print the value with some context, such as
fprintf('The mean is %f\n', mx);
Haya Ali
Haya Ali il 18 Mag 2021
Thanks a lot !

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Fourier Analysis and Filtering in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by