Borrar filtros
Borrar filtros

Add columns to excel file

5 visualizaciones (últimos 30 días)
Truc
Truc el 17 de Nov. de 2022
Respondida: William Rose el 22 de Nov. de 2022
I'm working on 12 lead ECG signals. Currently, the electrocardiogram machine can only measure 8 leads, and the remaining 4 leads are calculated according to the following formula:
Lead III = Lead II - Lead I
avR = - (Lead I + Lead II)/2
avL = Lead I - (Lead II/2)
avF = Lead II - (Lead I/2)
How can I add these 4 leads to the file excel?
For example:
heading_column={'Time','Lead I','Lead II','Lead III','avR','avL','avF','V1','V2','V3','V4','V5','V6'};
Now I have exported 8 leads to file excel. Help me please!
Code:
while get(hObject,'Value')
data = fscanf(s, '%s');
sa = str2num(data);
if(size(sa,2)>8)
ei=ei+1;
ecgdata(ei,:)=[sa(1) sa(2:9)./6116.69333333-685.71];
if(get(handles.pushbutton1,'Value'))
e1=sa(2);
e1=e1./6116.69333333-685.71;%1000*((e1/32768)-1/2)*4.8/3.5;
e2=sa(3);
e2=e2./6116.69333333-685.71;%1000*((e2/32768)-1/2)*2*2.4/3.5;
e3=e2-e1;
temp=sa(1)/1000;
x=[x temp];
ecg1 = [ecg1 e1];
ecg2 = [ecg2 e2];
ecg3 = [ecg3 e3];
end
end
function pushbutton4_Callback(hObject, eventdata, handles)
global ecgdata;
heading_column={'Time','Lead I','Lead II','V1','V2','V3','V4','V5','V6'};
xls_filename= strcat(datestr(now,'yyyy_mm_dd_HH_MM_SS_'),'ECGdata.xls');
xlswrite(xls_filename,heading_column,1,'A3');
xlswrite(xls_filename,ecgdata,1,'A4');
  4 comentarios
William Rose
William Rose el 22 de Nov. de 2022
@Truc, please post the Excel file with the data.
I am going to be busy, so I may not be able to answer your quesiton, but others will be more able to assist you, if you post the file.
Truc
Truc el 22 de Nov. de 2022
Thanks bro! This is my file data

Iniciar sesión para comentar.

Respuestas (3)

Marcel
Marcel el 17 de Nov. de 2022
Editada: Marcel el 17 de Nov. de 2022
Im not sure if this is going to help you, but im writing data into a table, and i was asked if i could export that to a xls file, so i came up with the following code. Maybe you can adopt it
function exportExcel(app)
newColumn = app.UITable.ColumnName(~cellfun('isempty',app.UITable.ColumnName));
newColumn = reshape(newColumn, 1, size(newColumn, 1));
newData = app.UITable.Data(1,:);
% e.g. C:\path\subfolder\
workingDir = getpref("settings", "workingDir");
xlsFile = workingDir + "\\" + date + "\\report.xls";
% get file length
if isfile(xlsFile)
filelen = length(readcell(xlsFile));
if filelen == 0
writecell([cellstr(newColumn);cellstr(newData)], xlsFile);
else
writecell(cellstr(newData), xlsFile, 'WriteMode','append');
end
else
writecell([cellstr(newColumn);cellstr(newData)], xlsFile);
end
end
My Table

William Rose
William Rose el 22 de Nov. de 2022
It seems to me far easier to add the missing leads in Excel. The attached Excel workbook has columns added for leads III, aVR, aVL, aVF.
The sampling rate is too low to capture some important details. For example, the R wave height in leads I and II varies significantly, because the samples sometimes miss the actual peaks. If the numbers in the Time column are in milliseconds, as I suspect, then the sampling rate is 1/.021=47.6 Hz. The consensus recommendation of the AHA and ACC and Heart Rhythm Society (2007) is a samplling rate of at least 500 Hz, and over 1 kHz, if pacemaker spikes are to be detected.
The interbeat intervals are remarkably constant. Was this patient on a pacemaker? I do not see pacing spikes, but they would be probably missed at the sampling rate used here, since a typical pacing spike is <0.5 msec.
The EKG is normally band-pass filtered, which will make the mean value of each lead be very close to zero. The leads in your file have mean values very different from zero. That may be something you want to consider.

William Rose
William Rose el 22 de Nov. de 2022
Code below reads the data from the .xls file and adds channels III, aVR, aVL, avF.
%% Read data from xls file.
filename='2022_11_22_15_30_55_ECGdata';
filespecIn=[filename,'.xls'];
A=importdata(filespecIn);
%% Compute missing leads.
L3=A.data(:,3)-A.data(:,2); %III=II-I
aVR=-(A.data(:,2)+A.data(:,3))/2; %aVR=-(I+II)/2
aVL=(A.data(:,2)-L3)/2; %aVL=(I-III)/2
aVF=(A.data(:,3)+L3)/2; %aVF=(II+III)/2
%% Insert missing leads into the data array.
% Use standard column ordering: time,I,II,III,aVR,aVL,aVF,V1,...,V6
A.data=[A.data(:,1:3), L3, aVR, aVL, aVF, A.data(:,4:9)];
A.textdata=[A.textdata(1:3),'Lead III','aVR','aVL','aVF',A.textdata(4:9)];
%% Write new xls file.
filespecOut=[filename,'+4a.xls'];
T=array2table(A.data,'VariableNames',A.textdata);
writetable(T,filespecOut)
Try it. Good luck.

Categorías

Más información sobre Data Import and Analysis en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by