How to convert a 1x1 struct to double matrix (error using pan tompkin)?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Student
el 1 de Jun. de 2024
I'm trying to use Pan Tompkins code to detect QRS from ECG signal, and I'm facing a problem, the code defines ecg as vector, but there's part of the code function that uses this line:
ecg_h = filtfilt(a,b,ecg);
But ecg has to be a double matrix for filtfilt function to work. I tried loading the signal before defining it as ecg because it gets loaded as double matrix, but that didn't work, I kept getting undevined variable error.
% Load data
ecg=load('ECGdata.mat');
fs = 500; % Sampling frequency
t = (0:length(ecg)-1) /fs;
gr=1;
QRS=pan_tompkin(ecg,fs,gr);
3 comentarios
Respuesta aceptada
Stephen23
el 2 de Jun. de 2024
Editada: Stephen23
el 2 de Jun. de 2024
"Originally, I didn't put the semicolon, I only added it because MATLAB error system recommended it. I did remove it and there's no difference."
Of course it will not change any results from your code: the semicolon simply suppresses displaying those code results, it will not change what the results are. Image Analyst asked you to display the results and to "tell us what you see in the command window"... which you did not do. There is not much point in following only half of their advice.
Unless you are debugging you should use the semicolon.
"I kept getting undevined variable error."
After fixing your incorrectly-named Mfile (wrong name, spaces, wrong extension) everything works as expected:
matstruct = load('ECGdata.mat');
ecg = matstruct.x;
fs = 500; % Sampling frequency
t = (0:numel(ecg)-1) / fs;
gr = 1;
QRS = pan_tompkin(ecg,fs,gr)
heartRate = calculateHeartRate(QRS, fs)
1 comentario
Más respuestas (0)
Ver también
Categorías
Más información sobre ECG / EKG 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!