MATLAB: Cant find cause of non-singleton

bsxfun

Dear All,
I am using ga tool to optimize a vector for A*x-B=0
I conclude with the help of this forum http://www.mathworks.co.uk/matlabcentral/answers/41852-ga-fitness that a fitness function like this:
FitnessFcn = @(x)sum(abs(bsxfun(@minus,sum(bsxfun(@times,A,x),2),B)),1)
is working for the example below for A <5×4>
A =
2.1000 3.4000 101.0000 -2.0000
1.1000 -89.0000 33.0000 56.0000
-49.0000 -0.1900 92.0000 31.0000
4.2000 5.2000 0.1000 19.0000
40.0000 22.0000 12.0000 44.0000
and B <5x1>
B =
104.5000
1.1000
73.8100
28.5000
118.0000
By using [x]=ga(FitnessFcn,4)
But when I import file A <2100×24> and B <2100×1> (checked in the workspace tab)
I take :
??? Error using ==> bsxfun
Non-singleton dimensions of the two input arrays must match each other.
Error in ==> @(x)sum(abs(bsxfun(@minus,sum(bsxfun(@times,A,x),2),B)),1)
Error in ==> validate>@(x)fitness(x,FitnessFcnArgs{:}) at 136
fitness = @(x) fitness(x,FitnessFcnArgs{:});
Error in ==> fcnvectorizer at 14
y(i,:) = feval(fun,(pop(i,:)));
Error in ==> makeState at 47
Score = fcnvectorizer(state.Population(initScoreProvided+1:end,:),FitnessFcn,1,options.SerialUserFcn);
Error in ==> gaunc at 41
state = makeState(GenomeLength,FitnessFcn,Iterate,output.problemtype,options);
Error in ==> ga at 279
[x,fval,exitFlag,output,population,scores] = gaunc(FitnessFcn,nvars, ...
Caused by:
Failure in user-supplied fitness function evaluation. GA cannot continue.
I would be really grateful for your help since its really odd for me this behavior. Thanks for your time
Chris

Best Answer

Usually dbstop if error helps to reveal such problems. Then Matlab stops, when the error occurs and you can inspect the current dimensions of the variables.