フィルターのクリア

Code for Base Matrix

1 回表示 (過去 30 日間)
Fayyaz
Fayyaz 2014 年 7 月 4 日
編集済み: Andrei Bobrov 2014 年 7 月 4 日
Hello All.
I've a matrix, A=61312*3
1st column: from 1 to 246 (survey no, total 61312 surveys at 246 location, for a vehicle from origin to destination) 2nd column: from 1 to 81 (Origin) 3rd column: from 1 to 81 (Destination)
I need to create a base matrix (81*81) which shows the no. of vehicles among these origins and destinations.
Kindly help me out.

採用された回答

Andrei Bobrov
Andrei Bobrov 2014 年 7 月 4 日
編集済み: Andrei Bobrov 2014 年 7 月 4 日
[a,~,ii] = unique(A(:,2));
[b,~,jj] = unique(A(:,3));
out1 = accumarray([ii,jj],A(:,1),[max(ii), max(jj)],@(x){x});
out = [[{nan};num2cell(a(:))],[num2cell(b(:)');out1]];
ADD
out1 = accumarray([ii,jj],1);
out = [[nan;a(:)],[b(:)';out1]];
  2 件のコメント
Fayyaz
Fayyaz 2014 年 7 月 4 日
Thanks for this. Actually I need the total sum for each 1 to 81 origin and destination. Your code was OK for my previous link question, but unfortunately not for this. Can you check it again? or let me know if you didn't understand my question well.
Andrei Bobrov
Andrei Bobrov 2014 年 7 月 4 日
Hi Muhammad! Please try code after word ADD in this answer.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangePhased Array Design and Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by