diff --git a/@miSim/run.m b/@miSim/run.m index a0f8329..b0517d7 100644 --- a/@miSim/run.m +++ b/@miSim/run.m @@ -10,7 +10,12 @@ function [obj] = run(obj) % Start video writer if obj.makeVideo v = obj.setupVideoWriter(); + drawnow; v.open(); + % Capture reference frame size; used to resize frames that deviate + % due to figure reflow during plot updates (e.g. in headless mode). + I_ref = getframe(obj.f); + videoFrameSize = [size(I_ref.cdata, 2), size(I_ref.cdata, 1)]; end end @@ -73,6 +78,9 @@ function [obj] = run(obj) % Write frame in to video if obj.makeVideo I = getframe(obj.f); + if size(I.cdata, 2) ~= videoFrameSize(1) || size(I.cdata, 1) ~= videoFrameSize(2) + I.cdata = imresize(I.cdata, [videoFrameSize(2), videoFrameSize(1)]); + end v.writeVideo(I); end end diff --git a/util/objectiveFunctionWrapper.m b/util/objectiveFunctionWrapper.m index 0a9de95..c7cd743 100644 --- a/util/objectiveFunctionWrapper.m +++ b/util/objectiveFunctionWrapper.m @@ -10,6 +10,9 @@ function f = objectiveFunctionWrapper(center, sigma) f (1, 1) {mustBeA(f, "function_handle")}; end + if size(sigma, 1) == 1 && size(center, 1) > 1 + sigma = repmat(sigma, size(center, 1), 1, 1); + end assert(size(center, 1) == size(sigma, 1)); f = @(x,y) sum(cell2mat(arrayfun(@(i) mvnpdf([x(:), y(:)], center(i,:), squeeze(sigma(i, :, :))), 1:size(center,1), "UniformOutput", false)), 2); end \ No newline at end of file