このコードを使用してマトリックスを作成しました。
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.
このエラーの原因は誰にもわかりますか?