Average number of y for y=f(x) where there are several y values for the same x
1 回表示 (過去 30 日間)
古いコメントを表示
I have an array y where y is a function of x but for every x there are multiple values of y.
x=[x1 x1 x1 x1 x1 x2 x2 x2 x2 x3 x3 x3 x3 x3 ...]
y=[y1 y2 y3 y4 y5 y6 ... yn]
How can I separate the values of y related to each unique x and e.g. calculate their average (or maximum or minimum) to have an array of unique x and y elements at the end that would look like this:
x=[x1 x2 x3 ... xn]
y=[mean(y1:y5) mean(y6:y9) mean(y10:y14)...]
0 件のコメント
採用された回答
Voss
2022 年 2 月 4 日
% creating some x and y to replicate your situation, as I understand it:
x = repelem([1 2 3 4],1,5);
y = randn(size(x))+repelem(2:2:8,1,5);
disp(x); disp(y);
% Perform the requested task, as I understand it:
[ux,~,jj] = unique(x);
nux = numel(ux);
uy = zeros(1,nux);
for ii = 1:nux
uy(ii) = mean(y(jj == ii));
end
disp(ux); disp(uy);
0 件のコメント
その他の回答 (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!