フィルターのクリア

Dividing a set of values into groups

15 ビュー (過去 30 日間)
Mohamed Saleh
Mohamed Saleh 2018 年 2 月 13 日
コメント済み: Abdalla Issa 2020 年 11 月 5 日
Hi. Please, I need a help with the following. I have a set of very larg number of values. For simplicity, let I have the values x=[-2,-7,-1,-6,-1,-5,-2,-3,-1]. I want to divide x into four sets. The first set x1={-2,-7}, the second set x2={-1,-6}, the 3th is x3={-1,-5} and x4={-2,-3}. taking into account that the last value of x which is -1 is not included as I divide x into four groups. Then I need to find the mean for each set and compare it with each other. Your answer is really appreciated. Thank you.
  2 件のコメント
Jelle
Jelle 2018 年 2 月 14 日
Are you asking on how to calculate the average for each consecutive quarter of the data, independent of the number of datapoints?
Mohamed Saleh
Mohamed Saleh 2018 年 2 月 14 日
編集済み: Mohamed Saleh 2018 年 2 月 14 日
Thank you very much for your interest. I created my code and solved the problem already. Cheers

サインインしてコメントする。

採用された回答

Akira Agata
Akira Agata 2018 年 2 月 14 日
Here is one possible solution.
% Your data
x = [-2,-7,-1,-6,-1,-5,-2,-3,-1];
% Number of group
nGroup = 4;
% Number of element per each group
nElementPerGroup = floor(numel(x)/nGroup);
% Create a group index
group = repelem((1:nGroup),nElementPerGroup);
% Average of each group
avg = splitapply(@mean,x(1:numel(group)),group);
  2 件のコメント
Mohamed Saleh
Mohamed Saleh 2018 年 2 月 14 日
Thank you very much. It works well now.
Abdalla Issa
Abdalla Issa 2020 年 11 月 5 日
I have a different problem similar to this, my values (8000 values) are in a separeta file I uploaded the file but now I need to divide these values into bands starting from the minimum value each band will cover 1.5.
so the first band will have to cover all the values included between the minimum value and minimum value+1.5
how can I do it?
thank you.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLanguage Fundamentals についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by