Filter löschen
Filter löschen

My code is not producing the anticipated figure for a time, EKG signal plot

2 Ansichten (letzte 30 Tage)
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')
Warning: Column headers from the file were modified to make them valid MATLAB identifiers before creating variable names for the table. The original column headers are saved in the VariableDescriptions property.
Set 'VariableNamingRule' to 'preserve' to use the original column headers as table variable names.
data = 15×16 table
x_ElapsedTime_ x_i_ x_ii_ x_iii_ x_avr_ x_avl_ x_avf_ x_v1_ x_v2_ x_v3_ x_v4_ x_v5_ x_v6_ x_vx_ x_vy_ x_vz_ ______________ ______ ______ ______ ______ ______ ______ ______ ______ ______ _____ _____ _____ ______ _____ ______ {'00:00.000'} -0.244 -0.229 0.015 0.237 -0.13 -0.107 -0.044 -0.12 -0.056 0.106 0.197 0.195 -0.002 0.06 -0.009 {'00:00.001'} -0.242 -0.234 0.009 0.238 -0.126 -0.113 -0.042 -0.117 -0.051 0.11 0.202 0.198 -0.002 0.061 -0.01 {'00:00.002'} -0.241 -0.234 0.007 0.238 -0.124 -0.114 -0.044 -0.118 -0.053 0.11 0.201 0.197 -0.004 0.056 -0.009 {'00:00.003'} -0.241 -0.229 0.012 0.235 -0.126 -0.109 -0.045 -0.117 -0.051 0.112 0.201 0.197 -0.002 0.053 -0.008 {'00:00.004'} -0.232 -0.227 0.004 0.23 -0.118 -0.112 -0.045 -0.117 -0.05 0.112 0.2 0.199 0.001 0.054 -0.009 {'00:00.005'} -0.226 -0.233 -0.007 0.23 -0.11 -0.12 -0.051 -0.121 -0.053 0.107 0.196 0.194 0 0.056 -0.009 {'00:00.006'} -0.225 -0.236 -0.011 0.231 -0.106 -0.124 -0.052 -0.121 -0.054 0.106 0.194 0.193 0.001 0.058 -0.008 {'00:00.007'} -0.234 -0.234 0.001 0.234 -0.117 -0.117 -0.049 -0.117 -0.051 0.112 0.199 0.199 0.002 0.052 -0.008 {'00:00.008'} -0.234 -0.233 0.002 0.234 -0.118 -0.116 -0.051 -0.118 -0.05 0.111 0.201 0.197 0.001 0.048 -0.007 {'00:00.009'} -0.224 -0.235 -0.012 0.23 -0.105 -0.124 -0.055 -0.12 -0.054 0.108 0.198 0.194 0 0.049 -0.006 {'00:00.010'} -0.221 -0.231 -0.011 0.226 -0.104 -0.121 -0.054 -0.123 -0.054 0.109 0.199 0.195 0.001 0.053 -0.007 {'00:00.011'} -0.227 -0.228 -0.001 0.228 -0.113 -0.115 -0.057 -0.122 -0.053 0.108 0.198 0.196 0.003 0.062 -0.005 {'00:00.012'} -0.232 -0.226 0.006 0.229 -0.119 -0.11 -0.053 -0.119 -0.052 0.109 0.198 0.198 0.003 0.061 -0.005 {'00:00.013'} -0.237 -0.23 0.008 0.234 -0.122 -0.112 -0.051 -0.12 -0.051 0.111 0.199 0.199 0.001 0.05 -0.005 {'00:00.014'} -0.244 -0.233 0.012 0.238 -0.128 -0.111 -0.049 -0.119 -0.052 0.113 0.199 0.202 0.001 0.053 -0.005
% 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');

Akzeptierte Antwort

Cris LaPierre
Cris LaPierre am 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');
Warning: Column headers from the file were modified to make them valid MATLAB identifiers before creating variable names for the table. The original column headers are saved in the VariableDescriptions property.
Set 'VariableNamingRule' to 'preserve' to use the original column headers as table variable names.
% 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');

Weitere Antworten (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by