taking average and saving to new file
2 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
Michael Haderlein
2014 年 8 月 22 日
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 件のコメント
Michael Haderlein
2014 年 8 月 22 日
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).
参考
カテゴリ
Help Center および File Exchange で Get Started with MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!