insulin pump output, newbie here
Show older comments
Hello, I am a new user, starting small here by trying to make an x/y plot with data from my insulin pump. The software provides a .csv file, from there I would like to create a script within matlab to read the file, and plot the results in a graph. There is a header in the file, and the parameter names start on line 11, this will/should stay constant. What I'm wondering for starters is how to import the csv, and get the data into MATLAB. I'd like to plot day by day, with timestamp column/BG reading.
Any helps/books or references are appreciated. Thanks!
Sample file attached below
Answers (2)
Star Strider
on 8 May 2015
0 votes
It would help to have a sample of your actual data file, since it’s impossible to determine how your data are arranged.
I expect that you would read it with xlsread, but we need to see how the dates are imported to write code to read and plot it.
8 Comments
Star Strider
on 8 May 2015
my8950’s ‘Answer’ moved here...
gotcha, I see you can attach files here too. File attached. Basically I want to start simple, and just plot column D and Column F. I'd like to get to the point of being able to create one diagram per day of data. I can generate this file to show maybe 20 days or so. Just to see if I can spot trends, stuff like that, to get me started using MATLAB.
Star Strider
on 8 May 2015
No file yet. Use the ‘paperclip’ icon, then ‘Choose File’ and ‘Attach File’.
I’m interested in this because I’m a physician Board Certified in Internal Medicine, and I trained in Endocrinology and Diabetology at UCSF many, many years ago. I then went back to get my M.S. in Biomedical Engineering. (Retired now.)
Star Strider
on 8 May 2015
my8950’s ‘Answer’ moved here...
Sample file
Star Strider
on 8 May 2015
We have a problem. I’m not getting any date-time information or column headers that might tell me what I’m seeing. I was expecting a cell array of strings for the dates.
Run this to see what I’m getting:
[d,s,r] = xlsread('my8950 CareLink-Export-1431105641591.csv');
data = d(1:5,[1:3 36:end]); % Numeric Data
strg = s(1:5,:); % String Data
raw = r(1:5,:); % Raw Data
Does the documentation on your device have any information on what data are in those columns? (Note that I eliminated a bunch of NaN values in the ‘data’ assignment, so it only looks at the first five rows of columns [1,2,3,36,37,38]).
my8950
on 8 May 2015
Star Strider
on 8 May 2015
Edited: Star Strider
on 9 May 2015
Open it in Excel and you get an entirely different file! It’s obvious that xlsread isn’t going to work. It may be some kind of proprietary file format that Excel can read but xlsread has problems with.
I can get textscan to read the tab-delimited text-file version of it (that I created using Excel, and that you will have to do with your data if you are to read it in MATLAB). I attached the text file here.
This is not as efficient as I would like it, but it works:
fidi = fopen('my8950 CareLink-Export-1431105641591.txt');
d = textscan(fidi, ['%f%s%s%s%s%f' repmat('%s',1,33)], 'HeaderLines', 11, 'Delimiter','\t', 'EndOfLine','\r\n');
DT = d{4};
BG = d{6};
DT = DT(~isnan(BG));
BG = BG(~isnan(BG));
dn = datenum(DT);
figure(1)
plot(dn, BG)
datetick('x', 'mm/dd HH:MM')
grid
EDIT —
I wasn’t happy until I could get the insulin as well, even though you didn’t request it. (Chalk it up to my diabetes research experience.) This code is a revision of the previous that also finds and plots insulin doses and times:
fidi = fopen('my8950 CareLink-Export-1431105641591.txt');
d = textscan(fidi, ['%f%s%s%s%s%f%s%s%s%s%s%f' repmat('%s',1,27)], 'HeaderLines', 11, 'Delimiter','\t', 'EndOfLine','\r\n');
DT = d{4}; % Date-Time Cell Array
BG = d{6}; % Blood Glucose Cell Array
DTG = DT(~isnan(BG)); % Blood Glucose Times
BG = BG(~isnan(BG)); % Blood Glucose Values
dng = datenum(DTG); % Blood Glucose Date Numbers
Insc = d{12}; % Insulin Bolus Cell Array
Insi = ~isnan(Insc); % Insulin Bolus Logical Indices
Ins = Insc(Insi); % Insulin Bolus Values
DTI = DT(Insi); % Insulin Bolus Times
dni = datenum(DTI); % Insulin Bolus Date Numbers
figure(1)
plot(dng, BG)
hold on
stem(dni, Ins, '^', 'Filled')
hold off
datetick('x', 'mm/dd HH:MM')
grid
legend('Blood Glucose (mg/dL)', 'Insulin (IU)')
This is without question the most difficult file I’ve ever dealt with! If you have the inclination, ask Medtronic to allow you to export it as a simple text file with the columns you choose.
Star Strider
on 11 May 2015
my8950’s ‘Answer’ moved here ...
I did not see this until just now. I'll have to take your file and see, right now I have no idea. I'm just learning, so I'm using this file because I thought it was simple.
Star Strider
on 11 May 2015
Apparently the application you’re using (provided by Medtronic?) made it seem simple. The problem is that for whatever reason, the dates do not import as date strings as they should in a normal Excel file, and all the other information appears as NaN. (If it imported as a normal Excel file, the code would have been much simpler. I tried every function I could think of to read it, and failed with all of them.) As it exists, you will have to manually export the file from Excel as a tab-delimited .txt file, then read it.
It would probably be easiest to see if you can export it directly from whatever you’re using to read it to a text file that MATLAB would have no problems with. I would include the insulin dosages as well, since to me, that is important information.
You might also contact Medtronic to see if they’ve developed MATLAB code to read it, or if they have any suggestions on how to export the information you want to a form MATLAB can easily read.
Anas El Fathi
on 20 Jul 2017
0 votes
Hello,
I am also trying to read the carelink data, this post has inspired my solution. I am reading glucose / insulin basal + bolus / Carbs. I converted the txt file to csv and fixed the numbers to use dot "." instead of "," for numbers.
Please find attached the csv file and the script I wrote.
Anas
Categories
Find more on Language Fundamentals 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!