How to convert a 1x1 struct to double matrix (error using pan tompkin)?
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Stephen23
le 2 Juin 2024
Modifié(e) : Stephen23
le 2 Juin 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 commentaire
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Single-Rate Filters dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!