My code is not producing the anticipated figure for a time, EKG signal plot
조회 수: 1 (최근 30일)
이전 댓글 표시
I wrote a code to import a csv file full of EKG data. I have cut it down for the purpose of space, but I have tried altering the cell formats to be mm:ss.SSS and adding 0's to make it exact, but it is not plotting anything. The amount of EKG signal samples (10,000) I have is up to 10 seconds, but the figure being produced is up to 20 minutes. I looked up the function of duration and implemented several of the examples from there, but this is the closest I have gotten to getting my code to run without errors, but it is not plotting anything. When I plot just the ekg data it creates a figure, but it isn't the correct EKG wave output form as the x-axis should be time and not samples (which is how it plots when just saying plotATM(ekg_data) in the command function). Any help would be appreciated.
% read the CSV file
data = readtable('samples (4).csv')
% extract the EKG signal column and convert to a numeric array
ekg_data = str2double(table2array(data(:, 2)));
% extract the time column and convert to a duration array
infmt = 'mm:ss.SSS';
time = duration(data{:, 1}, 'InputFormat', infmt);
% plot the EKG signal as time vs. signal
plot(time, ekg_data);
xlabel('Time');
ylabel('Signal (mV)');
title('EKG signal');
댓글 수: 0
채택된 답변
Cris LaPierre
2023년 4월 10일
Your code is good. I think the issues is with your str2double conversion. It is unnecessary, since that data is already a double. Remove that, and you code will plot.
Since your data is in a table, there is no need to covert it back to an array. See the Access Data in Tables page for more on how to use a table.
Here is your code with a couple small changes
% read the CSV file
data = readtable('samples (4).csv');
% extract the EKG signal column and convert to a numeric array
ekg_data = data.x_i_;
% extract the time column and convert to a duration array
infmt = 'mm:ss.SSS';
time = duration(data.x_ElapsedTime_, 'InputFormat', infmt,'format',infmt);
% plot the EKG signal as time vs. signal
plot(milliseconds(time), ekg_data);
xlabel('Time (ms)');
ylabel('Signal (mV)');
title('EKG signal');
추가 답변 (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!