How to split an array of tot seconds in windows of 60 sec haveing also windows without values?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi,
I have an array of around 2000sec. I want to split it in windows of 60sec.
The problem is that i have windows without any values and i want to calculate the length of every segment. How can i do?
My code works but the problem is that i have some rows of my matrix (a and b) without values after the third row because there is nothing there so i get the error.
Here my code:
clc; clear all;
ampl = [0.200996832776533,0.108288299408268,0.0108131653866189,0.0148501982585796,0.0297382659490564,0.0205780518568360,0.0363249885477546,0.0199522268771810,0.0153020371754288,0.0107487246066077,0.0100465831465900,0.0115319065471520,0.0171852396573782,0.0171052921316926,0.0136866723178271,0.0405302764516071,0.0134629777880290,0.0441825338391930,0.0307994156746245,0.0129757976302988,0.0289983735876320,0.0107446774084927,0.0113938663682375,0.0779717262951948,0.0297679211454362,0.0104621364653687,0.0162760758676064,0.0172718901202518,0.0118598151578763,0.0204114935244239,0.0111905531897566,0.0243914430076990,0.0124411275457071,0.0224448043041579,0.0199145559228095,0.0257484947120200,0.0105671896452576,0.0158831603271501,0.0152644217085658,0.0108627619307609];
amp = round(ampl*100)/100
o = [0.250000000000000,2.50000000000000,7.50000000000000,18.5000000000000,22.5000000000000,34.2500000000000,70.5000000000000,72.2500000000000,78.5000000000000,150.250000000000,330.250000000000,336,336.500000000000,340.250000000000,341.500000000000,395.250000000000,1133.25000000000,1142.75000000000,1152.25000000000,1155.25000000000,1177,1179.75000000000,1191,1214,1215.75000000000,1217.25000000000,1271,1334.25000000000,1335,1336.75000000000,1337.75000000000,1391.25000000000,1429,1447.25000000000,1457.50000000000,1458.75000000000,1461.50000000000,1473.25000000000,1593.25000000000,1598.25000000000];
onset = round(o*100)/100
a = [];
b = [];
l = [];
m = [];
d = [];
M = [];
y=round(onset(length(onset))/60);
for i=1:y
for j=1:length(onset)
if onset(j)>=(i-1)*60+1 && onset(j)<=i*60
a(i,j)= onset(j);
b(i,j)= amp(j);
end
end
% l(i) = length(nonzeros(b(i,:))); ERROR!! Index in position 1 exceeds array bounds (must not exceed 3).
0 commentaires
Réponses (2)
dpb
le 21 Nov 2021
Use discretize. In paricular, look at the third input form where the bins, and input arrays are durations (iow, convert your time to a duration first).
Alternatively, if there's more than just one variable (or even if not), look at using timetable and retime instead.
NB: there's really no need for the rounding, but if do want to, also note the second optional argument to round()
>> ampl=round(ampl,2);
>> ampl(1:3)
ans =
0.20 0.11 0.01
>>
2 commentaires
dpb
le 22 Nov 2021
I'd suggest going back to where you read the data in and use readtable and table2timetable there.
You can, of course, build a time table from the arrays already have, but it's extra steps to do so...
Star Strider
le 21 Nov 2021
I am not certain what the desired result is, however if I guess correctly the buffer function may be the solution.
.
0 commentaires
Voir également
Catégories
En savoir plus sur Matrices and Arrays dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!