フィルターのクリア

Matrix creation which identify link of vehicles

1 回表示 (過去 30 日間)
Fayyaz
Fayyaz 2014 年 7 月 4 日
回答済み: Jos (10584) 2014 年 7 月 11 日
Hello.
I've a matrix 61312*3.
1st column: from 1 to 81 (Origin place of a vehicle) 2nd column: from 1 to 81 (Destination place of a vehicle) 3rd column: from 1 to 246 (where the vehicle has surveyed)
There are 61312 observation (no. of rows) at 246 locations.
I need to create a matrix which shows that from origin (1 to 81) to Destination (1 to 81) which location (1 to 246) these vehicle follow. I think the order of the matrix will be 81*81.
Kindly let me know how should I proceed. thanks in advance.
  2 件のコメント
Andrei Bobrov
Andrei Bobrov 2014 年 7 月 4 日
repeated question
Fayyaz
Fayyaz 2014 年 7 月 4 日
Hello Andrei.
This is not the repeated question, both questions were different.

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

採用された回答

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]];
  5 件のコメント
Fayyaz
Fayyaz 2014 年 7 月 4 日
@Andrei Bobrov: The order of matrix is 81*246 which is fine, but the problem is in one cell there is a lot of information like brackets, value*double etc.
Fayyaz
Fayyaz 2014 年 7 月 4 日
編集済み: Fayyaz 2014 年 7 月 4 日
I've modified the code, as I need a matrix 81*81, but still I don't know how to get rid of such kind of values like 440x1 double
A=combinedfile;
[a,~,ii] = unique(A(:,1));
[b,~,jj] = unique(A(:,2));
out1 = accumarray([ii,jj],A(:,3),[max(ii), max(jj)],@(x){x});
out = [[{nan};num2cell(a(:))],[num2cell(b(:)');out1]];

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

その他の回答 (1 件)

Jos (10584)
Jos (10584) 2014 年 7 月 11 日
M = accumarray(A(:,[2 3]), A(:,1), [81 81], @(x) {x})

カテゴリ

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