identify peers within a firm - sparse matrix only

조회 수: 2 (최근 30일)
Long Hong
Long Hong 2020년 5월 16일
편집: Long Hong 2020년 5월 16일
Dear all:
This is a follow-up post from my previous one, which has been solved by @Image Analyst. Now I have encountered a new problem as I have increased my sample size by a lot.
The original problem is described as follows. The dataset contains worker ID and firm ID in each year. I hope to create a matrix that shows whether worker j is worker i's coworker. For example, if there are 5 workers and 2 firms in the dataset, the data structure look like below.
IDw IDf
1 1
2 2
3 1
4 2
5 2
Ideally, I hope to create a matrix C as follows:
As suggested by @Image Analyst, I could use the following code to create such a matrix:
firm2 = [firms(:), firms(:)];
distances = pdist2(firm2, firm2) == 0;
However, the code pdist2 requires a non-sparse matrix first. In my current case, it is a 0.7 million x 0.7 million matrix. My MATLAB could not handle such a matrix if it is non-sparse.
Therefor, I am wondering if anyone knows an alternative (quick) algorithm that could help me get a sparse matrix of C?
Thank you very much and I look forward to hearing from you!
Best,
Long

답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by