Getting different plot ranges

Trying to get time series plot of different days from dataset. Got help previoulsy but was only able to do day 1, when altering the code for day 2. It did not work. The csv file is opened, then columns are selected: Day 2 is from A61:D353, which then named glucose1_2 and is then imported to the workspace. Trying to get plot such as Day1 below for all remaining days of glucose.csv file.
Day 1 - A2:D60
Day2 - A61:D353
Day 3 - A354:D646
Day 4- A647:D940
Day 5 - A941:D1234
Day 6- A1235:D1439
glucose1_2.date.Format = 'dd.MM.uuuu HH:mm';
glucose1_2.time.Format = 'hh:mm:ss.S';
glucose1_2.date = [glucose1_2.date glucose1_2.time];
glucose1_2.glucose = glucose1_2.glucose*18;
Unrecognized field name "glucose".
plot(glucose1_2.date,glucose1_2.glucose);
grid on; legend('Patient1, Day1');
xlabel('Date and Time'); ylabel('Serum Glucose Level (mg/dl)');

 Risposta accettata

William Rose
William Rose il 19 Dic 2021
Modificato: William Rose il 19 Dic 2021
T=readtable('glucose.csv'); %read file into table T
You will see that T has columns named date, time, glucose.
Line below plots glucose vs. time for the rows which have date=2014-10-01.
plot(T.time(T.date=='2014-10-01'),T.glucose(T.date=='2014-10-01'));
Line below plots glucose vs. time for day 2: the rows which have date=2014-10-02. And so on.
plot(T.time(T.date=='2014-10-02'),T.glucose(T.date=='2014-10-02'));
Good luck with your work!

3 Commenti

Plot multiple days of glucose on one plot:
T=readtable('glucose.csv'); %read file into table T
datestring={'2014-10-01','2014-10-02','2014-10-03','2014-10-04'};
linesp={'-r','-g','-b','-m'};
figure;
for i=1:length(datestring)
plot(T.time(T.date==datestring{i}),T.glucose(T.date==datestring{i}),linesp{i});
hold on
end
legend(datestring{1},datestring{2},datestring{3},datestring{4})
I assume the units for glucose are mmol/L. If they are in mg/dL, the commonly used clinical units in the US, then the measurements are off, since these numbers are not compatible with life as we know it. :)
Yes I would have to multiply by 18. based on the code you sent do you know how I can alter it so the plot shows mgdl instead
@Nathaniel Porter, yes you can. Multiply y-values by 18 in the plot command. Include labels with units.
plot(T.time(T.date=='2014-10-02'),18*T.glucose(T.date=='2014-10-02'));
xlabel('Time (hours)'); ylabel('Plasma glucose (mg/dL)');
Try.

Accedi per commentare.

Più risposte (0)

Categorie

Prodotti

Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by