taking average and saving to new file
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
hey everybody... i am new to MATLAB.. i was facing problem with a small code.
i have a data file with about 100 points in x and y. i want to make a file with average of points in a bin of 3 i.e new x1 will be average of old(x1,x2,x3) and similarly for y...
Please guys help me out with it...
thanks :)
0 commentaires
Réponses (1)
Michael Haderlein
le 22 Août 2014
So, what should the new x2 be? The average of old (x2, x3, x4) or the average of old (x4, x5, x6)?
In the first case, it's basically smoothing the data. So you can use the smooth() function with a span of 3. Eventually, you want to remove the first and the last value after smoothing as they are the first and the last value of the original vectors (no mean here).
In the second case, you can use the following function if the length of x is multiple of 3:
xavg=mean(reshape(x,length(x)/3,3));
if the length is e.g. 100, I guess you only want to use the first 99 values. Then you can use
xavg=mean(reshape(x(1:3*fix(length(x)/3)),fix(length(x)/3),3));
3 commentaires
Michael Haderlein
le 22 Août 2014
Uhm, that's something entirely different?
binsize=10;
ind=1+fix(x/binsize);
x2=zeros(1,max(ind));
y2=zeros(1,max(ind));
for cnt=1:max(ind)
x2(cnt)=mean(x(ind==cnt));
y2(cnt)=mean(y(ind==cnt));
end
Don't know if there's a more elegant way, but this one works (at least in case that now is what you want).
Voir également
Catégories
En savoir plus sur Historical Contests 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!