Hi,
I want to organize heart rate by the time spent in 3 diferent categories: 0 - 50 bpm 50 - 100 bpm 100 - 200 bpm
what is the best code??
thank you

 Accepted Answer

One approach:
[~,sc] = xlsread('Sérgio Querido TEST.csv');
t_rc = regexp(sc(2:end), ';','split');
dn = cellfun(@(x) datenum(x(:,1), 'HH:MM:SS'), t_rc);
hr = cellfun(@(x) str2double(x(:,2)), t_rc);
bin_vct = [0 50 100 200];
hc = histcounts(hr, bin_vct);
fprintf(1, '\n\tRate\t0-50\t50-100\t100-200\n')
fprintf(1, '\tSecs\t%4d\t%6d\t%7d\t\n\n', hc)
Rate 0-50 50-100 100-200
Secs 3 320 0

6 Comments

Why error?? Can you explain all code??
I do not know what the problem is. The code I posted worked or I would not have posted it. I do not know of any changes in the cellfun or datenum functions between R2015a and R2017a (that I am using) that would throw that error. I no longer have access to R2015a, so I cannot test it in your version.
The code works by first splitting the time from the heart rate in the regexp call, since they are separated only by a semicolon. That should work in R2015a. It then converts the time to a date number in the first cellfun call, and converts the heart rate string to a double-precision numeric vector in the second cellfun call. The ‘bin_vct’ vector defines the edges of the bins for the histcounts function that then computes the histogram, and the final two fprintf calls print the results.
data = xlsread('hr.csv','B:B');
FCmax=200
FCrep=60
dataPERCENTAGE=(data*100)/FCmax
bin_vct = [40 60 70 80 90 100];
hc = histcounts(dataPERCENTAGE, bin_vct);
fprintf(1, '\n\tRate\t40-60\t60-70\t70-80\t80-90\t90-100\n')
fprintf(1, '\tSecs\t%2d\t%2d\t%2d\t%6d\t%6d\t\n\n', hc)
Rate 40-60 60-70 70-80 80-90 90-100
Secs 3669 2155 525 54 0
I solved my problem with this final code. How can i subtitute fprintf by a xlswrite? I want to organize rate and secs in a spreedsheet table. thank you for you help
My pleasure.
This works:
filename = 'HeartRateHistogram.xlsx';
V = {'Rate','40-60','60-70','70-80','80-90','90-100'; 'Secs',3669,2155,525,54,0};
xlswrite(filename, V)
Change it to work with your data and the file name you want.
I tested it and imported it with xlsread to check it.

Sign in to comment.

More Answers (1)

ES
ES on 28 Mar 2017

1 vote

use csvread to read the csv file.
you can then use the sort function or hist function for your need.

Categories

Community Treasure Hunt

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

Start Hunting!