Sizes mismatch: [1][6] ~= [1][1]

2 views (last 30 days)
xiaofu zhang
xiaofu zhang on 1 May 2019
I have use the function code as follow and use the MATLAB CODER to convert it to C code.But it has some error in the 'find' function.
The front of the function can be ignored, and the 'OC' is a matrix,'sci' is a integer. I just use the 'find' function and has the error as follow. The 'find' function i used in other funcion is right. The process of MATLAB CODER including generating trial code and building MEX is no error ,just in the running test file with MEX.
Could you give me some advice?Thanks a lot!
Error using SelectLeader (line 17)
Sizes mismatch: [1][6] ~= [1][1].
1function leader = SelectLeader(obj)
2 leng=length(obj.swarm);
3 sc=0;
4 GI=zeros(1,leng);
5 for i=1:leng
6 GI(i)=obj.swarm(i).GridIndex;
7 end
8 OC = unique(GI);
9 N = zeros(size(OC));
10 for k = 1:length(OC)
11 N(k) = length(find(GI==OC(k)));
12 end
13 P = exp(-obj.beta*N);
14 P = P/sum(P);
15 sci = RouletteWheelSelection(P);
16 sc = OC(sci);
17 SCM=find(GI==sc);
18 smi=randi([1 length(SCM)
19 sm = SCM(smi);
20 leader = obj.swarm(sm);
21 end

Answers (0)

Categories

Find more on MATLAB Coder in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!