How to convert a 1x1 struct to double matrix (error using pan tompkin)?
1 view (last 30 days)
Show older comments
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 Comments
Accepted Answer
Stephen23
on 2 Jun 2024
Edited: Stephen23
on 2 Jun 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)
More Answers (0)
See Also
Categories
Find more on ECG / EKG in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!