例如,我要转以下列:
[90; 175; 600; 650; 655; 660]
进入矩阵:
[ 90, 175, 600, 650, 655, 660; 175, 600, 650, 655, 660, 655; 600, 650, 655, 660, 655, 650; 650, 655, 660, 655, 650, 600; 655, 660, 655, 650, 600, 175; 660, 655, 650, 600, 175, 90]
我将使用哪种算法?
到目前为止,我有:
col = [90; 175; 600; 650; 655; 660]; [numrows, temp] = size(col); Z = zeros(numrows, numrows); for i = 1:1:numrows for j = 1:1:numrows Z(i,j) = col(i); Z(j,i) = col(i); end end
toeplitz几次翻转后,内置函数即可提供所需的内容:
toeplitz
>> col = [90; 175; 600; 650; 655; 660]; >> result = flipud(toeplitz(flip(col))) result = 90 175 600 650 655 660 175 600 650 655 660 655 600 650 655 660 655 650 650 655 660 655 650 600 655 660 655 650 600 175 660 655 650 600 175 90