MATLAB: Function ‘subsindex’ is not defined for values of class ‘cell’.

function 'subsindex' is not defined for values of class 'cell'.

function[E] = adjmatrix(adjmat)
echo off;
%N = max(max(adjmat));
N=max(max([adjmat{:}]));
%trans = eye(N,N,'single');
trans = zeros(N,N,'single');
l = size(adjmat,1)
for i = 1:l
r = (adjmat(i,1));
c = (adjmat(i,2));
trans(r,c) = 1;
% trans(r,c) = trans(r,c) + 1;
end;
maxE = trans;
in above code i have got following error how to solve it ??? Error using ==> subsindex Function 'subsindex' is not defined for values of class 'cell'.
Error in ==> createadj at 18
trans(r,c) = 1;
[EDITED, Jan, please format your code properly – thanks!]

Best Answer

adjmat is a cell, so you need curly braces to get the contents of an element:
for i = 1:l
r = adjmat{i,1}; % Curly braces!
c = adjmat{i,2};
trans(r,c) = 1;
end
The error message is clear. The debugger would help to identify the problem exactly. Type this in the command window:
dbstop if error
Then run the code again. When it stops at the error, examine the locally used variables, in this case their type.