MATLAB: How to do I separate in segments

segments

Dear all,
I have a certain numerical value (from 0 to 5) for every second from 0 to a time T. I now want to separate 0 to T in segments of 10 minutes each and calculate the % of each value (from 0 to 5) in each segment. I suppose that it is very simple, but I am new to matlab, so how do I do that?
Thank you very much in advance,
Anastasia

Best Answer

I’m not certain how your data are organised, but with my sample data, this works:
T = 60*60*24; % Secconds/Day
t = 0:T-1; % Time Vector
nv = randi([0 5], 1, T); % Data Vector
nv10 = reshape(nv, 600, []); % Create 10-Minute Segments
counts = hist(nv10, 6);
pct = bsxfun(@rdivide, counts, sum(counts))*100;
Data = nv10(:,1:3) % Sample Initial Data
Dist = counts(:,1:3) % Sample Counts
Pcts = pct(:,1:3) % Sample Percents
The last three lines aren’t necessary for the code. They just let you see the first three columns (30 minutes) of the results of the analysis.