Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In matlab Write a function gpxmeanheartrate that takes the name of a GPX file an

ID: 3845680 • Letter: I

Question

In matlab

Write a function gpxmeanheartrate that takes the name of a GPX file and returns the average heart rate of the tracking samples stored in that file. GPX (GPS Exchange Format) is an XML format used for sharing GPS tracking data. The heart rate information is enclosed by "<gpxtpx:hr>" and "</gpxtpx:hr>", e.g., one of the time points where the heart rate is 147 will contain the text: "<gpxtpx:hr>147</gpxtpx:hr>". Sample GPX files used in this problem are available at @/ftp/jogging.gpx and @/ftp/jogging_small.gpx.

Example:


Explanation / Answer

function avg = gpxmeanheartrate(fileName)
fileid = fopen(filename)
sum = 0;
count = 0;

tline = fgetl(fileid);
while ischar(tline) %read file line by line
    start = findstr('<gpxtpx:hr>', tline); %find in the tag is found
    if size(start) > 0 %if found
        stop = findstr('</gpxtpx:hr>', tline); %find the endex of terminator
        for i = 1:numel(start) %this takes care if single line contains multiple tags
            sum = sum + str2num(tline(start(i)+11:stop(i)-1)); %simple operation of extracting substring and add it to sum
            count ++; %increase count
        end
    end
    tline = fgetl(fileid);
end
fclose(fileid); %close file to prevent data loss
avg = sum/count; %find avg
end

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote