Vector form of for loop?
2 次查看(过去 30 天)
显示 更早的评论
I have a piece of code that works fine. But it has a for loop as below:
M=5;
N=10;
abc=0.0;
for m1=1:M*N
abc=abc+(abs(yo(m1,1)-ye(m1,1))).^2;
end
abc=abc/(M*N);
e=abc;
What will be its vectored form to reduce the execution time?
1 个评论
采纳的回答
Matt J
2022-11-21
编辑:Matt J
2022-11-21
e=norm(yo-ye).^2/M/N
4 个评论
Matt J
2022-11-21
编辑:Matt J
2022-11-21
Also is it true for any lenght of vector u?
Yes, try it.
can you make me understand on the line:
Perhaps an example,
steerA=randi(5,3,2)
steerB=randi(50,3,2);
%original version
steerM = zeros(size(steerA, 1)*size(steerB, 1), size(steerA,2));
for idxK = 1 : size(steerM,2)
steerM(:, idxK) = kron(steerB(:, idxK), steerA(:, idxK));
end
%new version
steerM2=steerA.*permute(steerB,[3,2,1]);
%compare
steerM,steerM2
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!