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=23866)

poster 2019-12-10 20:48

将行插入矩阵Matlab
 
我有一个〜100000/2矩阵。我想浏览一下各列,对每个垂直相邻的值求平均值,然后将该值插入两个值之间。例如...

1 2 3 4 4 6 7 8 会成为

1 2 2 3 3 4 3.5 5 4 6 5.5 7 7 8 我不确定在matlab中是否有简洁的方法可以做到这一点。我看了一下[URL="http://www.mathworks.com/matlabcentral/fileexchange/9984"]http://www.mathworks.com/matlabcentral/fileexchange/9984,[/URL]但似乎在特定点将矩阵中的所有行插入到另一行中。显然它仍然可以使用,但是只是想知道是否有更简单的方法。

任何帮助表示赞赏,谢谢。



[B]回答:[/B]

未经测试:

% Take the mean of adjacent pairs x_mean = ([x; 0 0] + [0 0; x]) / 2; % Interleave the two matrices y = kron(x, [1;0]) + kron(x_mean(1:end-1,:), [0;1]);

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


所有时间均为北京时间。现在的时间是 04:05

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