HKQuantity

Extracts quantity values from the Apple Health export.xml file
53 Downloads
Updated 17 Oct 2022

View License

Wearable health sensors opened the possibilty of continuously monitoring vital signs, by now the first adopters of smart watches have years of data at their disposal. At the same time, smartphones started to track the activity and distances that the owner walked. By now also third-party apps save their data into the Apple Health app, making it the most complete record that is accessible.
However, interpreting these large datasets on the phone to find correlations, trends, extremes, etc. is not optimal yet, or non-existent. MATLAB is made to perform complex smoothing, calculation, trend explorations of large datasets and can display them in beautiful graphs either for medical publications or personal use.
From the following categories are covered by the HKQuantity function: Activity, Body Measurements, Reproductive Health, Hearing, Vital Signs, Lab and Test Results, Nutrition, Alcohol, Consumption, Mobility, or UV Exposure.
The HKQuantity function includes an automatic suggestion and completion feature for the input names as well as code examples.
Loading the Apple Health data into MATLAB
Unzip the Apple Health "export.zip", in MATLAB select the now unzipped folder as 'Current Folder'. It should contain a file called "export.xml". Copy the following code to your matlab script to import the dataset in a cell vector.
Data = import('export.xml');
HKQuantity variables
The following quantity values can be exctracted if they are present in the dataset: 'StepCount','DistanceWalkingRunning','GroundContactTime','RunningPower','RunningSpeed','RunningStrideLength','RunningVerticalOscillation','DistanceCycling','PushCount','DistanceWheelchair','SwimmingStrokeCount','DistanceSwimming','DistanceDownhillSnowSports','BasalEnergyBurned','ActiveEnergyBurned','FlightsClimbed','NikeFuel','AppleExerciseTime','AppleStandTime','VO2Max','Height','BodyMass','BodyMassIndex','LeanBodyMass','BodyFatPercentage','Circumference','BasalBodyTemperature','EnvironmentalAudioExposure','HeadphoneAudioExposure','HeartRate','RestingHeartRate','WalkingHeartRateAverage','HeartRateVariabilitySDNN','OxygenSaturation','BodyTemperature','BloodPressureDiastolic','BloodPressureSystolic','RespiratoryRate','BloodGlucose','ElectrodermalActivity','ForcedExpiratoryVolume1','ForcedVitalCapacity','InhalerUsage','InsulinDelivery','NumberOfTimesFallen','PeakExpiratoryFlowRate','PeripheralPerfusionIndex','DietaryBiotin','DietaryCaffeine','DietaryCalcium','DietaryCarbohydrates','DietaryChloride','DietaryCholesterol','DietaryChromium','DietaryCopper','DietaryEnergyConsumed','DietaryFatMonounsaturated','DietaryFatPolyunsaturated','DietaryFatSaturated','DietaryFatTotal','DietaryFiber','DietaryFolate','DietaryIodine','DietaryIron','DietaryMagnesium','DietaryManganese','DietaryMolybdenum','DietaryNiacin','DietaryPantothenicAcid','DietaryPhosphorus','DietaryPotassium','DietaryProtein','DietaryRiboflavin','DietarySelenium','DietarySodium','DietarySugar','DietaryThiamin','DietaryVitaminA','DietaryVitaminB12','DietaryVitaminB6','DietaryVitaminC','DietaryVitaminD','DietaryVitaminE','DietaryVitaminK','DietaryWater','DietaryZinc','BloodAlcoholContent','NumberOfAlcoholicBeverages','AppleWalkingSteadiness','SixMinuteWalkTestDistance','WalkingSpeed','WalkingStepLength','WalkingAsymmetryPercentage','WalkingDoubleSupportPercentage','StairAscentSpeed','StairDescentSpeed', and 'UVExposure'.
Important: Keep the 'functionSignatures.json' file in the same folder as the HKQuantity function, for the automatic function suggestion and completion. Please cite me if you use my code for publications!

Cite As

Robert Schmidt (2024). HKQuantity (https://www.mathworks.com/matlabcentral/fileexchange/119188-hkquantity), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2021b
Compatible with R2021b and later releases
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes
1.0.0