Trying to remove Nans when plotting histogram, pdf and cdf

6 views (last 30 days)
clear;
load InsulinReadings.mat
xX2 = InsulinReadings;
xX2(xX2==0)=missing;
A2 = mean(xX2,'all',"omitnan")
B2 = median(xX2,'all',"omitnan")
C2 = max(xX2,[],'all',"omitnan")
D2 = min(xX2,[],'all', "omitnan")
figure
histogram(InsulinReadings(~isnan(InsulinReadings),128,'Normalization')
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.
xlabel('Insulin ng/dL')
%Now get pdf
[D PD] = allfitdist(xX2,'PDF');
xlabel('Insulin ng/dL');
%Now get the CDF
[D PD] = allfitdist(xGlucoseReadings,'CDF');
xlabel('Insulin ng/dL')

Accepted Answer

Voss
Voss on 25 Feb 2022
I think you basically have it right. I just "fixed" a syntax error on the line where you call histogram(). ("fixed" is in quotes because I can't be sure what you're going for there.)
(Also, looks like allfitdist.m has been removed from the File Exchange, so I can't run it, but maybe your copy does the right thing here - I don't know.)
clear;
load InsulinReadings.mat
xX2 = InsulinReadings;
xX2(xX2==0)=missing;
A2 = mean(xX2,'all',"omitnan")
A2 = 296.9102
B2 = median(xX2,'all',"omitnan")
B2 = 86.4899
C2 = max(xX2,[],'all',"omitnan")
C2 = 1.0226e+04
D2 = min(xX2,[],'all', "omitnan")
D2 = 3.6900e-07
figure
histogram(InsulinReadings(~isnan(InsulinReadings)),128)%,'Normalization')
xlabel('Insulin ng/dL')
%Now get pdf
[D PD] = allfitdist(xX2,'PDF');
Unrecognized function or variable 'allfitdist'.
xlabel('Insulin ng/dL');
%Now get the CDF
[D PD] = allfitdist(xGlucoseReadings,'CDF');
xlabel('Insulin ng/dL')
  6 Comments

Sign in to comment.

More Answers (0)

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by