I am receiving the error "Error using filter. Invalid data type. Input arrays must be numeric or logical." in the code
14 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Neha Sinha
el 13 de Dic. de 2022
Comentada: Neha Sinha
el 13 de Dic. de 2022
ecg = load('matlab_matrix.mat')
Fs = 200;
B_lp_1 = [1 zeros(1,5) -2 zeros(1,5) 1]/32;
A_lp_1 = [1 -2 1];
ecg_lp = filter(B_lp_1,A_lp_1,ecg); %Error here
ecg_lp = ecg_lp/max(ecg_lp);
Link for matlab_matrix.mat : https://drive.google.com/file/d/1TEwaK_w0GuQrT8vVUPB1BUCSSOYA2R6j/view?usp=share_link
How to rectify this error?
0 comentarios
Respuesta aceptada
Walter Roberson
el 13 de Dic. de 2022
when you load() and assign the output to a variable, the output becomes a struct with one field for each input variable in the .mat file.
You are then passing that struct into filter, instead of accessing the data from the struct.
ecg_struct = load('matlab_matrix.mat', 'ecg');
ecg = ecg_struct.ecg;
3 comentarios
Walter Roberson
el 13 de Dic. de 2022
ecg_struct = load('matlab_matrix.mat');
fn = fieldnames(ecg_struct);
if length(fn) ~= 1
fprintf(2, 'Warning: file contains %d different variables, arbitrarily picking the first: %s\n', length(fn), fn{1});
end
ecg = ecg_struct.(fn{1});
Más respuestas (0)
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!