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:
0 件のコメント
回答 (2 件)
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
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
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.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Resizing and Reshaping Matrices についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!