我使用以下代码创建了一个矩阵:
row=4;
column=5;
pop=5;
for ii = 1:(row*pop)
done = false;
while ~done
newRow = randi([0 2],column,1);
done = (sum(newRow)<12)...
&& (~any(diff([0;find(newRow);column+1])>3));
end
result(:,ii) = newRow;
end
result = permute(reshape(result,column,row,pop), [2 1 3]);
我得到一个矩阵结果(4,5,5)
,然后我想在特定行中再次随机并弹出由约束引起的。
for ii=1:pop;
while size(find(waktu_libur(:,:,ii)>20&waktu_libur(:,:,ii)<23),1)~=11,
%#condition that had to be fullfilled by matrix result.
for bb=1:row;
if find(waktu_libur(bb,:,ii)>20&waktu_libur(bb,:,ii)<23),
continue;
else
done = false;
while ~done
newRow = randi([0 2],column,1);
done = (sum(newRow)<12)...
&& (~any(diff([0;find(newRow);column+1])>3));
end
dummy = newRow;
dummy= permute(reshape(dummy,jum_bag,1), [2 1]); %#this matrix which is used to replace
result(bb:,ii)=dummy %#process replacing dummy to row in matrix result that still obey contraint.
end %#end looping if
end %# end looping for
end %#end looping while
end %# end looping for
我认为我的代码是正确的。但是运行后,它给出了这个错误:
??? Subscripted assignment dimension mismatch.
有谁看到导致此错误的原因?