필터 지우기
필터 지우기

Calculate average for 0.01 step in first column

조회 수: 2 (최근 30일)
Stefht
Stefht 2017년 9월 27일
편집: dpb 2017년 9월 28일
Dear guys, I try a lot of time to do this but till now I didn t have success. I have a matrix A in which I want calculate for step of 0.01 for column x the average corresponding to value in z.I want to obtain a new matrix like showed in the picture:

답변 (2개)

dpb
dpb 2017년 9월 27일
편집: dpb 2017년 9월 28일
I'd already posted this once but there was no Answer connected so I'll try again...
Presuming no missing data, use the native memory storage order by column to your advantage--
z=mean(reshape(A(:,3),10,[])); % reshape by 10 rows for M columns and average
B=[A(1:10:end,1) z.']; % build output array with wanted x and computed z vectors
You can build the final array in place without needing the temporary intermediate variable z, of course; easier to read without the extra layers of parentheses for tutorial purposes here.
  댓글 수: 1
Jan
Jan 2017년 9월 27일
편집: Jan 2017년 9월 27일
+1.
I'd already posted this once but there was no Answer connected
27-Sep-2017 15:12 UTC, I have strange problems with the forum's interface also. Some comments cannot be sent, because the contents of the page has changed. Or a reload of a page fails with a message concerning a too high server load.

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


Jan
Jan 2017년 9월 27일
You did not specify, if the data are dense. Do you have 10 measurements for all intervals? What is an efficient solution, if the number of measurements is not the same for each bin?
[n, edge, bin] = histcounts(x, 100:0.1:x(end));
result = splitapply(@mean, z, bin);
But I hesitate to trust 100:0.1:x(end) due to the old effect: (0:0.1:1) == 0.3. Perhaps we should convert the indexing to integer values:
[n, edge, bin] = histcounts(x*10, 1000:x(end)*10);
But I'm not really happy, because this relies on a hard coded factor.

카테고리

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