How to convert a 1x1 struct to double matrix (error using pan tompkin)?
1 回表示 (過去 30 日間)
古いコメントを表示
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);
採用された回答
Stephen23
2024 年 6 月 2 日
編集済み: Stephen23
2024 年 6 月 2 日
"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)
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で ECG / EKG についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!