Reputation: 155
I'm going to create an adjacency matrix from a cell array, but faced two main problems:
I don't know how to access to cell array's elements; so an adhoc method was used.
(and the most important) The code produces an error and the partial result is also a weird one!
The cell array is as the following image:
The code is as follows:
for i=1:N
L=size(Al{i});
Len=L(1,2);
for j=1:Len
elm=Al{i};
D=elm(i,j);
Adjm(i,D)=1;
end
end
The code produces this error:
P.S.: The code is part of a program to construct adjacency matrix to represent superpixels adjacency within an image. There may be a specific solution for that!
Upvotes: 0
Views: 161
Reputation: 10772
There are lots of ways your code could be made better, but the specific error you are seeing is because you want D=elm(1,j);
instead of D=elm(i,j);
. Note the 1
instead of i
.
A somewhat more efficient approach would be to do,
for i=1:numel(Al)
Adjm(i,Al{i})=1;
end
As with your code, this assumes that there are no empty elements in Al
.
Upvotes: 4