Grouping data in a matrx

2 ビュー (過去 30 日間)
Farai Mahachi
Farai Mahachi 2019 年 11 月 15 日
編集済み: KALYAN ACHARJYA 2019 年 11 月 15 日
I have a 2 column matrix with some data. The fist column represents a time index, and the second column represents data for that time index:
whatIhave.png
so I want to create a matrix that looks like the one below:
whatIwant.png
so that I can plot a scatter that looks the one below:
plotwhatIwant.png
I have tried findgroups without success. How best can I implement that?
Thanks a lot for your assistance.

採用された回答

KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 11 月 15 日
編集済み: KALYAN ACHARJYA 2019 年 11 月 15 日
time_data=[1 1 1 2 3 3 3 4 4];
data=[10 16 14 18 13 14 23 26 29];
time_data1=unique(time_data);
data_result=cell(1,length(time_data1));
for i=1:length(time_data1)
idx=find(time_data==time_data1(i));
data_result{i}=data(idx);
end
data_result
The resultant groups are saved in a cell array.
Results:
data_result =
1×4 cell array
[1×3 double] [18] [1×3 double] [1×2 double]
>> data_result{1}
ans =
10 16 14
>> data_result{2}
ans =
18
>> data_result{3}
ans =
13 14 23
>> data_result{4}
ans =
26 29

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by