如何在没有 for 循环的情况下编写以下八度代码?

How can I write the following octave code without a for loop?

对于以下八度代码片段:

stepTerm = zeros(3,1);
for i = 1:3
  stepTerm(i,1) = some97ElementRowVector * some97by3Matrix(:,i);
end

上面的代码可以不用for循环吗?

这可以使用 bsxfun and sum 如下:

stepTerm = sum(bsxfun(@times, 97ElementRowVector , 97by3Matrix.'),2)

stepTerm = sum(bsxfun(@times, 97ElementRowVector.' , 97by3Matrix)).'

有什么问题

stepTerm = (97ElementRowVector * 97by3Matrix).'; 

?

在 MATLAB 上,

clc
N = 1e6;    
a = rand(1,97);
B = rand(97,3);

tic
for ii = 1:N
    stepTerm0 = sum(bsxfun(@times, a.', B)).'; 
end
toc

tic
for ii = 1:N
    stepTerm1 = (a*B).';
end
toc

max(abs(stepTerm0 - stepTerm1))

给予

Elapsed time is 12.114381 seconds.
Elapsed time is  1.827436 seconds.
ans =
    2.4869e-014