MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   如何在MATLAB中从给定的输入数据生成以下矩阵和向量? (https://www.labfans.com/bbs/showthread.php?t=22869)

poster 2019-12-10 16:49

如何在MATLAB中从给定的输入数据生成以下矩阵和向量?
 
假设我有输入data = [1 2 3 4 5 6 7 8 9 10]和num = 4 。我想使用这些来生成以下内容:

i = [1 2 3 4 5 6; 2 3 4 5 6 7; 3 4 5 6 7 8; 4 5 6 7 8 9] o = [5 6 7 8 9 10] 这基于以下逻辑:

length of data = 10 num = 4 10 - 4 = 6 i = [first 6; second 6;... num times] o = [last 6] [B]在MATLAB中[I]自动执行[/I]此操作的最佳方法是什么?[/B]


回答:
这是使用函数[URL="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/hankel.html"]HANKEL[/URL]的一种选择:

>> data = 1:10; >> num = 4; >> i = hankel(data(1:num),data(num:end-1)) i = 1 2 3 4 5 6 2 3 4 5 6 7 3 4 5 6 7 8 4 5 6 7 8 9 >> o = i(end,:)+1 o = 5 6 7 8 9 10

[url=https://stackoverflow.com/questions/1675798]更多&回答...[/url]


所有时间均为北京时间。现在的时间是 20:19

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.