how to make sparse, group association

조회 수: 1 (최근 30일)
Michael Sohl
Michael Sohl 2015년 12월 2일
편집: Michael Sohl 2015년 12월 2일
I have a 129202x2 double and this represents different people's associations with certain "groups". On a row we have a group number (column1) och a person id (column2). I wish to create a sparse matrix when G(i,j)=1 means that person j is connected to group i. I would prefer the matrix to be symmetric. Don't send me the link to matlab sparse page, please. I don't get it.

채택된 답변

Guillaume
Guillaume 2015년 12월 2일
편집: Guillaume 2015년 12월 2일
" I would prefer the matrix to be symmetric." Why should it be? If person 1 and 2 are associated with group 4, it does not mean that person 4 is associated with group 1 and 2. There's not even a guarantee your matrix will be square unless you have the same number of groups as persons.
"Don't send me the link to matlab sparse page, please. I don't get it." Maybe you should try getting it, otherwise you won't get very far.
demodata = [1 5
1 3
2 4
1 4
2 1
3 2];
connections = sparse(demodata(:, 1), demodata(:, 2), 1)
Also note that your original storage is actually more efficient in term of memory than the sparse matrix since you don't have to store the '1' that carries no information.
  댓글 수: 1
Michael Sohl
Michael Sohl 2015년 12월 2일
편집: Michael Sohl 2015년 12월 2일
Thank you. The fact is that I have tried to read the description for S = sparse(i,j,v) loads of times. Can't digest the mathematical way of describing it though. Thanks again!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Sparse Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by