Calculate average for 0.01 step in first column

1 次查看(过去 30 天)
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 中查找有关 Resizing and Reshaping Matrices 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by