Calculating average and saving to a new file

조회 수: 2 (최근 30일)
aditi
aditi 2014년 8월 22일
답변: Guillaume 2014년 8월 22일
I have few points between 200 to 500 which are unevenly spaced.
I have to make a file with x and y as average of all ponts in interval of 10 (if there is no point in that interval it will give 0)
i.e for 200 to 500... i will have 1 point for 200 to 210 (which will b average of all points in this interval) then 2nd point for 211 to 220... and so on..
like if my file is:
202 10000
205 12000
211 30000 .... and so on
so new x1 = average of(202,205) and new y1 = average(10000,12000) bcoz only those 2 points of the file come under 1st interval of 10.
plz help me

답변 (2개)

Patrik Ek
Patrik Ek 2014년 8월 22일
편집: Patrik Ek 2014년 8월 22일
I am not exactly sure what you want to do, but the guess is that you have to set of points x and y. Then calculate average with mean and save the data to .mat file with save.
xm = mean(x); % mean of x
ym = mean(y); % mean of y
xym = join(xm,ym); % Create a struct to save the data to hold down the number of variables in the file
save('meanValues','xym'); % Save the data
Then to load the data use load('meanValues') and if you want to split up the struct again use split(xym).
  댓글 수: 1
aditi
aditi 2014년 8월 22일
i will explain with example...
4 20
2 24
6 33
11 22
17 222
29 344
now for limits of x 1 to 100 and for binning of value 10 i.e for intervals of 10 i will have 1 point for interval 1 to 10 which will be average of 4,2,6 in above example (as only these values lie in 1st interval of value 10) and corresponding y value will b average of y values associated with them. similarly 2nd value of x will be average of 11,17 as only these lie in next interval of 10 i.e 11-20... and so on... i hope i made my point clear

댓글을 달려면 로그인하십시오.


Guillaume
Guillaume 2014년 8월 22일
If I understood correctly what you want to do:
points = [4 20;2 24;6 33;11 22;17 222; 29 344];
[~, interval] = histc(points(:, 1), 1:10:101); %to find which interval the points belong to
xmeans = accumarray(interval, v(:, 1), [], @mean); %to average x according to interval
ymeans = accumarray(interval, v(:, 2), [], @mean); %to average y according to interval
meanpoints = [xmeans, ymeans];

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by