How to vectorize this for loop
Show older comments
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);
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!