Why do I receive this error "Invalid data type. Input arrays must be numeric or logical."?

Hi,
I have a couple of .csv files and I am trying to read them first and then filter them out in a loop. But when I use "readtable" to read the .csv file, I receive this error:
Error using filter
Invalid data type. Input arrays must be numeric or logical.
Error in bestalgo_combined_newdata (line 18)
y_n2=filter(b,a,y2);
But when I run the same code with "xlsread" (I know this is not recommended, but still...) I get no error, everything runs fine. Can someone help what's the issue?
I am just adding a part of my code, because I don't think the whole code is relevant, no matter I read one .csv file or several, issue remains.
clearvars;
%Filter design
fl=0;
fh=9000;
fs=40000;
array_pW=zeros(100,1);
y2=readtable('cross talking.csv');
%more file to read, removed%
x=readtable('continuous.csv');
for e=1:100
fl=fl+50;
[b,a]=ellip(2, 1, 40, [fl,fh]/(fs/2),'bandpass');
y_n2=filter(b,a,y2);
y_h2 = normalize(y_n2, 'range', [-1 1]);
power2=rms(y_h2)^2;
%more code, removed...%
end
Can someone help? Thanks.

 Accepted Answer

It seems file to read the data using "readtable" as shown below.
You can try "dbstop error" before running the code to locate where it goes wrong.
x= readtable("https://www.mathworks.com/matlabcentral/answers/uploaded_files/939564/cross%20talking.csv");
head(x)
ans = 8×1 table
Var1 ____ 2671 2669 2671 2668 2663 2665 2663 2665

4 Comments

Hi Chunru,
using "dbstop error" does not gives me any significant info. I get this:
>> normalized_weighted
Error using filter
Invalid data type. Input arrays must be numeric or logical.
Error in normalized_weighted (line 44)
y_n2=filter(b,a,y2);
18 y_n2=filter(b,a,y2);
K>> dbstop if error
@Giggs B.: as Chunru wrote you need to call
dbstop if error
before running your code, not after. Then when the error occurs it will then stop in debug mode, so you check all of the inut arguments and run commands, etc.
It looks like you use the table as an input to the filter function (you don't show the complete code). You can try to replace "readtable" by "readmatrix".

Sign in to comment.

More Answers (0)

Categories

Tags

Asked:

on 24 Mar 2022

Commented:

on 24 Mar 2022

Community Treasure Hunt

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

Start Hunting!