フィルターのクリア

How can I split an array into different arrays defined by an index?

2 ビュー (過去 30 日間)
Dr.Agos
Dr.Agos 2015 年 10 月 15 日
コメント済み: Mohammad Abouali 2015 年 10 月 16 日
Hello all,
I have a large array of household income data and an index for the spatial unit the household is located in.
A= [AT1,24566;
AT1,40521;
AT2,32512;
BE1,66542;
.
.
.]
I would like to transform that array into arrays according to the spatial index so I can compute GINI coefficients in a next step.
Thank you Dragos

採用された回答

Mohammad Abouali
Mohammad Abouali 2015 年 10 月 15 日
Is AT1 a variable storing a number? or did you mean
A={'AT1',24566;
'AT1',40521;
'AT2',32512;
'BE1',66542 ...}
if A is stored as above than to extract AT1 household incomes you could do:
AT1_HouseHoldIncome=cell2mat(A(strcmpi(A(:,1),'AT1'),2))
AT1_HouseHoldIncome =
24566
40521
  2 件のコメント
Dr.Agos
Dr.Agos 2015 年 10 月 16 日
I can think of another workaround. I assign to every region code a number (AT1 then becomes 1) and define my data as matrix. how would the code change?
Thanks a lot
Mohammad Abouali
Mohammad Abouali 2015 年 10 月 16 日
If A is matrix like:
A=[1,24566;
1,40521;
2,32512;
3,66542 ...]
then
AT1_HouseHoldIncome=A( A(:,1)==1 ,2);
so A(:,1)==1 pretty much masks all those rows in first column that are storing 1 and then A( A(:,1)==1, 2) returns the second column for those rows.
Refer to Logical Indexing for more info on these type of indexing in MATLAB.

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

その他の回答 (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