Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab 移动行向量值_Matlab - Fatal编程技术网

Matlab 移动行向量值

Matlab 移动行向量值,matlab,Matlab,如何像这样移动向量c的条目: c = [1; 2; 0]; x = [1; 2; 3]; y(1:3) = rightshift(c', 0:2) * x; % Should produce: % y(1) = [1; 2; 0]' * x; % y(2) = [0; 1; 2]' * x; % y(3) = [0; 0; 1]' * x; 要生成输出向量y?,请使用- 或者使用mod&bsxfun- N = numel(c) y = triu(c((mod(bsxfun(@minus

如何像这样移动向量
c
的条目:

c = [1; 2; 0];
x = [1; 2; 3];

y(1:3) = rightshift(c', 0:2) * x;

% Should produce:
% y(1) = [1; 2; 0]' * x; 
% y(2) = [0; 1; 2]' * x; 
% y(3) = [0; 0; 1]' * x;
要生成输出向量
y

,请使用-

或者使用
mod&bsxfun
-

N = numel(c)
y = triu(c((mod(bsxfun(@minus,[0:N-1]',0:N-1),N)+1).'))*x
N = numel(c);
c_ext = [zeros(N-1,1) ; c(:)]
y = c_ext(bsxfun(@plus,[N:-1:1]',[0:N-1]))*x
或者只使用
bsxfun
-

N = numel(c)
y = triu(c((mod(bsxfun(@minus,[0:N-1]',0:N-1),N)+1).'))*x
N = numel(c);
c_ext = [zeros(N-1,1) ; c(:)]
y = c_ext(bsxfun(@plus,[N:-1:1]',[0:N-1]))*x

这本质上是一种卷积:

y = conv(c(end:-1:1), x);
y = y(end-numel(c)+1:end);

令人惊叹的!谢谢我真的试过了,但我自己想不起来。^^^@StefanFalk真的没问题!是否
toeplitz(c,0:N-1)
应该是
toeplitz(c,1:N)
,因为如果从
0开始,我会收到警告:“警告:输入列的第一个元素与输入行的第一个元素不匹配。列赢得对角线冲突。”但是从
1开始
是完美的。@StefanFalk我想你可以忽略这个警告。当你在
c
中有其他元素时,比如如果
c=[8;4;5]
,你也会在
toeplitz(c,1:N)
中得到警告。这个答案也很好。但是(出于某种原因),我们不允许使用
convmtx()
conv()
来执行
-循环。我得说这个问题来自一项作业。