How to vectorize this for loop
显示 更早的评论
Hello.Here's my codes from a program.I want to improve its efficiency,so I try to vectorize for loop.But I'm just a beginner in coding.I can't figure it out.Hope anyone who mastering in Matlab can help me to solve this.Thanks.
K = 10;
N = 10;
M = 10;
X(1:10,1:10) = 1;
seed_num = 123;
rng(seed_num);
B = abs(randi([1,100],M,N))
a = [];
m = [];
for l = 1:K
for j = 1:N
for k = 1:M
num = X(l,k)*B(k,j);
a = [a,num];
end
m = [m,max(a)];
a = [];
end
end
S = sum(m);
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!