count the values based on ID and create a new matrix

Input:
LAT LON VALUE
12.4 91.4 4
31.4 45.6 1
45.9 91.5 2
18.4 96.4 3
11.4 75.6 2
25.9 51.5 4
12.4 91.4 4
31.4 45.6 2
45.9 91.5 2
As you can see some of the lat lon's are repeated with different values, so I want to know for a lat lon, how many times (count) a values is observed. I have a input matrix of (90,000, 3)
LAT LON cnt = 1 cnt=2 cnt=3 cnt =4
12.4 91.4 0 0 1 2
31.4 45.6 1 1 0 0
45.9 91.5 0 1 2 0
18.4 96.4 0 0 1 0
11.4 75.6 0 1 0 0
25.9 51.5 0 0 0 1
I tried table, I could not figure out.

9 件のコメント

KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 2 月 10 日
Is it OK with cell arrays?
sample={'LAT' 'LON' 'cnt=1' 'cnt=2' 'cnt=3' 'cnt=4';12.4 91.4 1 0 3 0;31.4 45.6 2 4 0 9;45.9 91.5 10 0 9 20}
sample =
'LAT' 'LON' 'cnt=1' 'cnt=2' 'cnt=3' 'cnt=4'
[12.4000] [91.4000] [ 1] [ 0] [ 3] [ 0]
[31.4000] [45.6000] [ 2] [ 4] [ 0] [ 9]
[45.9000] [91.5000] [ 10] [ 0] [ 9] [ 20]
nlm
nlm 2019 年 2 月 10 日
makes no sense.
madhan ravi
madhan ravi 2019 年 2 月 10 日
Give an example of your desired output explicitly.
nlm
nlm 2019 年 2 月 10 日
Input:
LAT LON VALUE
12.4 91.4 4
31.4 45.6 1
45.9 91.5 2
18.4 96.4 3
11.4 75.6 2
25.9 51.5 4
12.4 91.4 4
31.4 45.6 2
45.9 91.5 2
As you can see some of the lat lon's are repeated with different values, so I want to know for a lat lon, how many times (count) a values is observed. I have a input matrix of (90,000, 3)
LAT LON cnt = 1 cnt=2 cnt=3 cnt =4
12.4 91.4 0 0 1 2
31.4 45.6 1 1 0 0
45.9 91.5 0 1 2 0
18.4 96.4 0 0 1 0
11.4 75.6 0 1 0 0
25.9 51.5 0 0 0 1
Look foward to your help. Thank you
nlm
nlm 2019 年 2 月 10 日
[ii,jj,kk]=unique(M,'rows','stable');
out=[ii,accumarray(kk,1)];
I get the count for each value, like this
963 66 4 3
963 67 3 1
963 68 3 1
963 69 3 1
963 67 4 2
963 68 4 2
963 69 4 2
however, I cannot get it in the form like this,
val=1 val=2 val=3 val=4
963 66 0 0 0 3
963 67 0 0 1 2
963 68 1 2
963 69 1 2
madhan ravi
madhan ravi 2019 年 2 月 10 日
Which version of matlab are you using?
nlm
nlm 2019 年 2 月 10 日
2018a
madhan ravi
madhan ravi 2019 年 2 月 10 日
Well good then :
t=[12.4 91.4 4
31.4 45.6 1
45.9 91.5 2
18.4 96.4 3
11.4 75.6 2
25.9 51.5 4
12.4 91.4 4
31.4 45.6 2
45.9 91.5 2];
T=array2table(t,'VariableNames',{'LAT','LON','COUNT'})
groupsummary(T,{'LAT','LON','COUNT'}) % gives almost your result but in more compact way
nlm
nlm 2019 年 2 月 10 日
I have already tried it, as mentioned earlier. It does not give me the form that I'm looking for. I need it like this
LAT LON cnt = 1 cnt=2 cnt=3 cnt =4
12.4 91.4 0 0 1 2
31.4 45.6 1 1 0 0
45.9 91.5 0 1 2 0
18.4 96.4 0 0 1 0
11.4 75.6 0 1 0 0
25.9 51.5 0 0 0 1

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

回答 (1 件)

Image Analyst
Image Analyst 2019 年 2 月 10 日

1 投票

Use unique() to get unique rows. Then for each unique row (lat,lon combination), call histogram.

3 件のコメント

nlm
nlm 2019 年 2 月 10 日
編集済み: Image Analyst 2019 年 2 月 10 日
[a,~,c] = unique((M),'rows');,
Hist =histogram(a);
It's a figure, could I get it in matrix form ?
Image Analyst
Image Analyst 2019 年 2 月 10 日
Hist is an object. Look at it's properties and methods and you'll know what to do. Take the semicolon off of that line to see the properties.
nlm
nlm 2019 年 2 月 10 日
編集済み: nlm 2019 年 2 月 10 日
I did, doesn't help.
Error in matlab.graphics.chart.primitive.Histogram/get.BinCounts

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

カテゴリ

ヘルプ センター および File ExchangeData Distribution Plots についてさらに検索

質問済み:

nlm
2019 年 2 月 10 日

コメント済み:

nlm
2019 年 2 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by