问题描述
A = [1 2 3; 4 5 6; 7 8 9];
现在,重塑矩阵A以形成行向量将得到B.
Now reshaping the matrix A to form a row vector gives B.
B = [1 4 7 2 5 8 3 6 9];
求多项式函数
f(x)=(7x + 6x ^ 2 + 3x ^ 3)mod 9因为存在9个元素,所以将'x'的值放在(1,...,9)范围内.
f(x) = (7x+6x^2+3x^3)mod 9 by putting values for 'x' ranging from (1,...,9) since there are 9 elements.
例如对于x = 1,f(x)= 16 mod 9 = 7
Ex. For x=1, f(x) = 16 mod 9 = 7
对于x = 2,f(x)= 62 mod 9 = 8直到x = 9导致置换.
For x=2, f(x) = 62 mod 9 = 8 till x = 9 results in permute.
permute = [7 8 3 1 2 6 4 5 9];
置换向量给出位置.使用矩阵索引,根据置换向量排列行向量B中元素的位置,从而产生enc.
permute vector gives positions. Using matrix indexing, the positions of elements in row vector B are arranged according to permute vector resulting in enc.
enc = B(permute);
%enc = [3 6 7 1 4 8 2 5 9]
因此,元素A中元素的原始位置已经改组,由new_A表示.
Thus, the original position of elements in A has been shuffled represented by new_A.
new_A = [3 1 2;6 4 5;7 8 9]; %reshaping new_A = (enc,3,3)
要获得原始矩阵,请再次将new_A重塑为行向量'dec'.
To get original matrix back, new_A is reshaped into a row vector 'dec' again.
dec = [3 6 7 1 4 8 2 5 9];
dec(permute) = dec;
dec = [1 4 7 2 5 8 3 6 9];
org_mat= reshape(dec,3,3)
org_mat = [1 2 3; 4 5 6; 7 8 9];
dec(permute)= dec如何在其中工作?
How does dec(permute)= dec works in this?
推荐答案
之所以起作用,是因为dec = enc = B(permute)
.
The reason it works is because dec = enc = B(permute)
.
如果仅将其替换为dec(permute) = dec;
,则会得到dec(permute) = B(permute)
(仅替换第二个dec
.)这将为您提供dec=B
.
If you simply replace this into dec(permute) = dec;
you get dec(permute) = B(permute)
(only replace the second dec
.) This gives you dec=B
.
这是一般结果.例如,对于任何排列向量p
以及向量X
和Y
,则如果设置X(p)=Y(p)
则X=Y
,因为将Y
中的第p个元素放入因此完全保留了Y
.
This is a general result. For example, for any permutation vector p
and vectors X
and Y
then if you set X(p)=Y(p)
then X=Y
because your placing the p'th element from Y
into the p'th element in X
thus exactly preserving Y
.
最后,由于dec=B
是您使用B=reshape(A,1,9)
创建的B
,所以reshape(dec,3,3)
当然会返回A
,因为这等效于reshape(B,3,3)
,只是撤消了原始的重塑.
Finally, since dec=B
and you created B
using B=reshape(A,1,9)
then of course, reshape(dec,3,3)
gives you back A
as this is equivalent to reshape(B,3,3)
which just undoes the original reshape.
我希望这会有所帮助.
这篇关于我有一个A = 3×3矩阵,其中要根据多项式函数结果对元素的位置进行混洗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!