view mt_get_transmat_at.m @ 4:931e71c24aa3

Old mt_get_transmat_at is now mt_get_transmat_near; new mt_get_transmat_at gets nearest transmat deterministically.
author samer
date Sun, 05 Feb 2012 13:34:02 +0000
parents ffd7efa3e5c0
children 80e9103b057f
line wrap: on
line source
% mt_get_transmat_at - Get transition matrix nearest given point in information space.
%
% mt_get_transmat_at ::
%    mt_system ~'Melody Triangle system structure',
%    natural   ~'voice Id (1 or greater)',
%    K:natural ~'size of transition matrix',
%    real      ~'X-coordinate',
%    real      ~'Y-coordinate'
% -> [[K,K]]   ~'transition matrix',
%    [[1,3]]   ~'information coordinates'.
%
% The selected transition matrix will be shown using mt_show_transmat,

function [T,P,I]=mt_get_transmat_at(Sys,Id,K,X,Y)
	logK=log(K);
	normpos = Sys.map([X;Y])';
	target = normpos*logK;
	tmats = Sys.transmats{K};
	info = Sys.info{K};
	L = size(info,1);

	% distance from target
	d2 = sum((info(:,1:2) - repmat(target,L,1)).^2,2);
	[dummy,J]=min(d2);
	T = tmats(:,:,J);
	I = info(J,:);
	mt_show_transmat(Id,T,I);
	if nargin>1, P=Sys.revmap(I(1:2)'/logK); end
end