Vector form of for loop?

5 views (last 30 days)
Sadiq Akbar
Sadiq Akbar on 21 Nov 2022
Commented: Sadiq Akbar on 22 Nov 2022
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?

Accepted Answer

Matt J
Matt J on 21 Nov 2022
Edited: Matt J on 21 Nov 2022
e=norm(yo-ye).^2/M/N
  4 Comments
Sadiq Akbar
Sadiq Akbar on 22 Nov 2022
Thanks a lot dear Matt J for your kind help.Regards,

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!