Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Logical Sparse matrices

Subject: Logical Sparse matrices

From: Rahul Singhal

Date: 13 Jan, 2010 06:39:03

Message: 1 of 4

Hi all:
  I am trying to form adjacency matrix of directed graph using sparse matrices.
for this i am using the following graph theory function:

A = sparse(x,y,true,50,50)

where x and y are the row matrices showing connections between different vertices.

for making x and y , I am using following rand function:
x = randi(50,1,60)
x = randi(50,1,60)

when i run the A = sparse(x,y,true,50,50), many times it shows the error whenever there are repeated indices..
Error using ==> sparse
Repeated indices are not supported for sparse logical matrices.

How can i create x and y so that is doesn't show this error. or is there ant other way of forming x and y matrices.. i even tried to change the rand stream for x and y , but it doesn't work.

Subject: Logical Sparse matrices

From: Bruno Luong

Date: 13 Jan, 2010 07:51:03

Message: 2 of 4

You might use my SETSPARSE on FEX http://www.mathworks.com/matlabcentral/fileexchange/23488-sparse-sub-access

A = sparse(zeros(1,0),zeros(1,0),true(1,0),50,50)
x=[1 1 50]
y=[2 2 50]
A = setsparse(A, x, y, true)

Bruno

Subject: Logical Sparse matrices

From: Bruno Luong

Date: 13 Jan, 2010 08:21:05

Message: 3 of 4

Another way is call UNIQUE with ROWS options to discard duplicated indexes before calling SPARSE

Bruno

Subject: Logical Sparse matrices

From: Jos (10584)

Date: 13 Jan, 2010 09:58:03

Message: 4 of 4

"Rahul Singhal" <rsinghalomatic@gmail.com> wrote in message <hijpq6$ckr$1@fred.mathworks.com>...
> Hi all:
> I am trying to form adjacency matrix of directed graph using sparse matrices.
> for this i am using the following graph theory function:
>
> A = sparse(x,y,true,50,50)
>
> where x and y are the row matrices showing connections between different vertices.
>
> for making x and y , I am using following rand function:
> x = randi(50,1,60)
> x = randi(50,1,60)
>
> when i run the A = sparse(x,y,true,50,50), many times it shows the error whenever there are repeated indices..
> Error using ==> sparse
> Repeated indices are not supported for sparse logical matrices.
>
> How can i create x and y so that is doesn't show this error. or is there ant other way of forming x and y matrices.. i even tried to change the rand stream for x and y , but it doesn't work.

A 50-by-50 (double) sparse matrix is not that big. I would suggest:

MyLogicalSparseMatrix = logical(sparse(x,y,1,50,50))

Jos

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us