3

我在 Matlab 中有 36x80 矩阵。它由 3x2 阵列组成,这些阵列是盲文的符号。IE

0 0 0 1 0 1 0 0 .....
0 1 0 0 1 0 0 0 .....
0 1 0 1 0 1 1 1 .....
.....................

其中第一个 3x2 子矩阵代表“p”字母

0 0 
0 1
0 1

接下来是“r”等等。我有许多代表盲文符号的“模式”3x2 矩阵。

如何将那个大矩阵翻译成英文字符矩阵?

4

1 回答 1

2

您可以将此矩阵转换为元胞数组,例如:

Bs = mat2cell(B,repelem(3,size(B,1)/3),repelem(2,size(B,2)/2));

B你的原始矩阵在哪里。

您必须以相同的方式准备盲文代码,以便将其与矩阵进行比较:

letters = {'p',[0 0;0 1;0 1];'r',[0 1;0 0;0 1]}; % ...and so on for all letters

然后你可以循环Bs

txt = char(zeros(size(Bs))); % the result
for k = 1:numel(Bs)
    for l = 1:size(letters,1)
        if isequal(Bs{k},letters{l,2})
            txt(k) = letters{l,1};
            break
        end
    end
end

这是另一种选择,无需将矩阵转换为元胞数组:

BB = reshape(reshape(B,3,[]),3,2,[]);
txt = char(zeros(size(B,1)/3,size(B,2)/2)); % the result
for k = 1:size(BB,3)
    for l = 1:size(letters,1)
        if isequal(BB(:,:,k),letters{l,2})
            txt(k) = letters{l,1};
            break
        end
    end
end

这应该更快,尤其是在您有大量数据的情况下。

于 2016-10-12T20:27:31.033 回答