1

First of all the output of 'find_nbrs' is a row vector. I get the following error (Subscript indices must either be real positive integers or logicals.) at line 13 when evaluating the following code:

function [ N ] = componentt( A,m,found_list )
found_list=[m];
for i = find_nbrs(m,A)
    found_list(length(found_list)+1)=i;
end
v=[];
    for j=found_list
       v=[v find_nbrs(j,A)];       
    end
    v=unique(v);

  while length(v)~= length(found_list)
           found_list = [found_list v(end)];  
      for k=v
          a=find_nbrs(k,A);
        while ~ismember(a,found_list)
            v(length(v)+1)=a;
        end
      end
  end


N=sort(found_list); %The entries of the output vector are in increasing order.
end
Federico
  • 23
  • 4
  • which one is line number 13? and can you post the values of variables – dnit13 Jan 27 '16 at 06:46
  • line 13 is: found_list = [found_list v(end)]; A is square matrix, m is a natural number between 1 and length(A) and found_list is an empty vector []. – Federico Jan 27 '16 at 06:48
  • Possible duplicate of [Subscript indices must either be real positive integers or logicals, generic solution](http://stackoverflow.com/questions/20054047/subscript-indices-must-either-be-real-positive-integers-or-logicals-generic-sol) – sco1 Jan 27 '16 at 12:23

1 Answers1

1

There are two possible reasons for the

Subscript indices must either be real positive integers or logicals.

error being thrown by the line

found_list = [found_list v(end)];

The first is that you somehow created a variable called end. But since you have posted an entire function which should be scoped I don't think that this is the case.

The second is that v is an empty matrix. In this case what is end? It might be 0. It's definitely not a positive integer though. Try this

v = [];
v(end)

and you'll get the error.

So you need to ask yourself if v should ever be empty by the time you hit that line. If it is, then you need to wrap it in an if statement. So something like

if ~isempty(v)
    found_list = [found_list v(end)];  
end
Dan
  • 45,079
  • 17
  • 88
  • 157