让X成为一台机器。更具体地说,我将其表示为3乘3乘2乘N阵列,其中N是状态数。将其视为一排N 3乘3矩阵,并在其后面显示另一个此类层。后面的层给出状态转换,前面的层给出输出值。所以说我从状态N开始并输入(x,y),我得到输出X(x,y,1,N)然后移动到状态X(x,y,2,N)。对于一系列输入(x,y)...(x',y')我想知道输出序列,并且我当前正在使用以下代码。任何加速建议都会非常受欢迎。一个相关的问题是' isequal'在比较矩阵行时比在比较单元格条目时更快地工作(与另一个相关'检查'代码而不是下面的代码)。
function [ T, O ] = mealy( X ,w ,k )
%Given a Mealy machine X, input word w and starting state k, T == 1 means
%this mealy machine does not have sufficient information to give an output
%for input word w. Else T == 0 and O is the output sequence for w.
L = length(w);
S = zeros(1,L); %state sequence
O = cell(1,L); %letter and output sequence
T = 0;
S(1) = k; %start from state k
% build output sequence O from input word w
for i = 2:L
e = w{i-1};
S(i) = X(e(1),e(2),2,S(i-1));
if S(i) < 0, T = 1; return, end
t = X(e(1),e(2),1,S(i-1));
if t < -1.5, T = 1; return, end
O{i-1} = [e(1),e(2),t];
end
e = w{L};
t = X(e(1),e(2),1,S(L));
if t < -1.5, T = 1;return, end
O{L}= [e(1),e(2),t];
end