My code is not producing the anticipated figure for a time, EKG signal plot
1 view (last 30 days)
Show older comments
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 Comments
Accepted Answer
Cris LaPierre
on 10 Apr 2023
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');
More Answers (0)
See Also
Categories
Find more on Annotations 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!