Error using wavedec Expected X to be finite. Error in wavedec (line 34) validateattributes(x,{'numeric'},{'vector','finite','real'},'wavedec','X');
조회 수: 19 (최근 30일)
이전 댓글 표시
I am using wavedec to discritize my signal using 'db4' wavelet.
my X = acceleration vector(9000 x 1)
My X is finite. But I am getting a error that ' Error using wavedec Expected X to be finite'
My code :
[a,l] = wavedec(acc,3,'db4');
approx = appcoef(a,l,'db4');
[acd1,acd2,acd3] = detcoef(a,l,[1 2 3]);
figure
subplot(4,1,1)
plot(approx)
title('Approximation Coefficients')
subplot(4,1,2)
plot(acd3)
title('Level 3 Detail Coefficients')
subplot(4,1,3)
plot(acd2)
title('Level 2 Detail Coefficients')
subplot(4,1,4)
plot(acd1)
title('Level 1 Detail Coefficients')
please help me. Where I am wrong. I am unable to solve this problem.
댓글 수: 1
Carlos Eduardo
2024년 5월 23일
Hola, hermano, perdona por contestar tantos años tarde y en español, el problema puede radicar de dos situaciones, la primera es que el vector es incorrecto (obvio ahí lo dice) pero puede ser ue tengas una columna que enumere tus datos, lo cual es un porblema, el formato .txt ya organiza los datos y la última y es así cómo encontré solución, le tienes que agregar ceros a la izquierda de tus datos, por ejemplo si tienes un 41 y un 1023, lo que tienes que hacer para que los lea como un mismo vector es agregar los respectivos ceros a la izquierda, por ejemplo 00041 y 01023.
Espero le sea de ayuda a alguien más.
답변 (1개)
Prasanna
2024년 9월 30일
Hi Arvind,
The error message you are encountering, "Expected X to be finite," indicates that the ‘wavedec’ function is detecting non-finite values (such as NaN or Inf) in your input vector acc. Although you mentioned that your data is finite, you can verify it programmatically using the below code to ensure there are no unexpected values. For Assumption, I am taking a random 9000x1 vector as the acceleration vector.
acc = rand(9000,1);
% Check for non-finite values
if any(~isfinite(acc))
error('Input vector contains non-finite values.');
end
% Clean the input vector (if necessary)
acc = fillmissing(acc, 'linear'); % Replace NaNs with linear interpolation
% Verify the input vector
assert(all(isfinite(acc)), 'Input vector must be finite.');
[a,l] = wavedec(acc,3,'db4');
approx = appcoef(a,l,'db4');
[acd1,acd2,acd3] = detcoef(a,l,[1 2 3]);
figure
subplot(4,1,1)
plot(approx)
title('Approximation Coefficients')
subplot(4,1,2)
plot(acd3)
title('Level 3 Detail Coefficients')
subplot(4,1,3)
plot(acd2)
title('Level 2 Detail Coefficients')
subplot(4,1,4)
plot(acd1)
title('Level 1 Detail Coefficients')
The above code gives the following as output:
For more documentation on the used functions, you can refer to the following links:
- ‘isfinite’: https://www.mathworks.com/help/releases/R2019b/matlab/ref/double.isfinite.html
- ‘fillmissing’: https://www.mathworks.com/help/releases/R2019b/matlab/ref/fillmissing.html
Hope this helps!
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Signal Analysis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!