Incorrect use of the function zeros().

4 visualizaciones (últimos 30 días)
Massilon Toniolo da Silva
Massilon Toniolo da Silva el 31 de Mayo de 2017
Comentada: Stephen23 el 31 de Mayo de 2017
I have tried the following piece of script and got problems related to the use of zeros():
X = X(:);
N = length(X);
measurement_values(n)= zeros(1,tau); % tau=20
for n = 1:tau
y_tau=zeros(1,N/tau); % Line 27 ---> Error appears here.
for j = 1:N/n
y_tau(j) = mean(X(((j-1)*n+1):j*n));
end
measurement_values(n) = SampEn(y_tau,r,m);
end
Error report:
Error using zeros Size inputs must be integers.
Error in MSE (line 27) y_tau=zeros(1,N/tau);
Is there a way to fix the problem?
I checked the tutorial but still could not solve the problem.
Many thanks,
Massilon

Respuesta aceptada

Stephen23
Stephen23 el 31 de Mayo de 2017
Editada: Stephen23 el 31 de Mayo de 2017
As the error message clearly states, the inputs to zeros must be integer values (e.g. 0, 1, 2, ...). With your code you are supplying a fractional value of N/tau:
y_tau = zeros(1,N/tau)
which does not make any sense because how many zeros would you expect from, for example:
zeros(1,2.5)
???
The solution is to ensure that you supply integer values to zeros.
  2 comentarios
Massilon Toniolo da Silva
Massilon Toniolo da Silva el 31 de Mayo de 2017
Hi Stephen, thanks for your answer. Yes, I agree completely. This code is not my own code. Surely, something is missing. I have thought to use the ceil(). But then there is a problem caused by too many arguments. Is there still a way of using the function ceil()? Many thanks, Massilon
Stephen23
Stephen23 el 31 de Mayo de 2017
y_tau = zeros(1,ceil(N/tau))

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Scan Parameter Ranges en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by