poster
2019-12-10, 20:30
有一个简单的方法如何产生以下矩阵:
a = 4 5 6 7 3 4 5 6 2 3 4 5 1 2 3 4 向量[1 2 3 4 5 6 7]沿对角线的投影是什么?
谢谢
回答:
您可以使用函数HANKEL (http://www.mathworks.com/access/helpdesk/help/techdoc/ref/hankel.html)和FLIPUD (http://www.mathworks.com/access/helpdesk/help/techdoc/ref/flipud.html)进行此操作:
a = flipud(hankel(1:4,4:7)); 或使用功能TOEPLITZ (http://www.mathworks.com/access/helpdesk/help/techdoc/ref/toeplitz.html)和FLIPLR (http://www.mathworks.com/access/helpdesk/help/techdoc/ref/fliplr.html) :
a = toeplitz(fliplr(1:4),4:7); a = toeplitz(4:-1:1,4:7); %# Without fliplr 您还可以将这些解决方案推广到任意矢量,在该矢量中您选择了要中断矢量的中心点。例如:
>> vec = [6 3 45 1 1 2]; %# A sample vector >> centerIndex = 3; >> a = flipud(hankel(vec(1:centerIndex),vec(centerIndex:end))) a = 45 1 1 2 3 45 1 1 6 3 45 1 上面的示例将向量的前三个元素放在第一列,并将向量的最后四个元素放在第一行。
更多&回答... (https://stackoverflow.com/questions/2594429)
a = 4 5 6 7 3 4 5 6 2 3 4 5 1 2 3 4 向量[1 2 3 4 5 6 7]沿对角线的投影是什么?
谢谢
回答:
您可以使用函数HANKEL (http://www.mathworks.com/access/helpdesk/help/techdoc/ref/hankel.html)和FLIPUD (http://www.mathworks.com/access/helpdesk/help/techdoc/ref/flipud.html)进行此操作:
a = flipud(hankel(1:4,4:7)); 或使用功能TOEPLITZ (http://www.mathworks.com/access/helpdesk/help/techdoc/ref/toeplitz.html)和FLIPLR (http://www.mathworks.com/access/helpdesk/help/techdoc/ref/fliplr.html) :
a = toeplitz(fliplr(1:4),4:7); a = toeplitz(4:-1:1,4:7); %# Without fliplr 您还可以将这些解决方案推广到任意矢量,在该矢量中您选择了要中断矢量的中心点。例如:
>> vec = [6 3 45 1 1 2]; %# A sample vector >> centerIndex = 3; >> a = flipud(hankel(vec(1:centerIndex),vec(centerIndex:end))) a = 45 1 1 2 3 45 1 1 6 3 45 1 上面的示例将向量的前三个元素放在第一列,并将向量的最后四个元素放在第一行。
更多&回答... (https://stackoverflow.com/questions/2594429)