0
temp(i,1) = rand(1)*(pb(1,num).pos(i,1) - pw(1,num).pos(i,1));

This line gives the following error:

Error using ==> minus
Not enough input arguments.

The following are the definitions of pb and pw.

pw=struct('fitness',[],'pos',{});
pb=struct('fitness',[],'pos',{});

pos is a 2 x 1 array.

Suever
  • 64,497
  • 14
  • 82
  • 101

4 Answers4

1

When tracking down errors like this, I break the problem up into smaller bits. Especially when the logic isn't readily apparent. Not only does it provide a path that can be used to step through your function using the debugger, but it also makes it more readable.

I've taken liberty with the intermediate variable names.

thisPb    = pb(1,num);
thisPw    = pw(1,num);
initialPos= pw.pos(i,1);
finalPos  = pb.pos(i,1);
whos initialPos finalPos 
temp(i,1) = rand(1) * (finalPos - initialPos);

The line with whos will print out the values. Make sure that finalPos and initialPos are both numbers.

Celso
  • 176
  • 1
  • 9
1

One way that you can get this error is when num is an empty matrix.

Mohsen Nosratinia
  • 9,844
  • 1
  • 27
  • 52
1

The expression

>> s(x).a

can return a variable number of outputs, depending on the size of x.

If x = [1,2,3] for example, it will return three values (as long as s has at least three elements).

If x = [] on the other hand, then s(x).a will return no outputs, so the expression

>> disp(s(x).a)

will give you a Not enough input arguments error, which is almost certainly what you're seeing. You should check that num is not empty.

Chris Taylor
  • 46,912
  • 15
  • 110
  • 154
0

Are you sure, that all values are really initialised? Try to check this before your codeline.

disp(pb(1,num).pos(i,1))
disp(pw(1,num).pos(i,1))
temp(i,1) = rand(1)*(pb(1,num).pos(i,1) - pw(1,num).pos(i,1));
  • When i write the above mentioned lines above my codeline there are valid values printed on the screen but after the values there is the following error message: Error using ==> disp Not enough input arguments. – user2452541 Jun 04 '13 at 16:52
  • @user2452541 can you add a `disp(num)` before? – Schorsch Jun 04 '13 at 17:01