How to eliminate for loop and perform the computation parallely?
Show older comments
Hi, I am looking a way to reduce the time for computation of the problem of this size. This code is a larger part of a big code where this code is ran several 100 times.
The data will be as large as shown in the code. I am looking a way to eliminate the loop and perform complete problem in a sigle go, to make this step fast. Could some one propose a solution without disturbing the fomulation through matrix multiplication istead of loop?
clear all;
close all;
fs = 35000;
T = 100; % s
Nt = fs*T;
M = 60;
a1 = randn(M,Nt);
a2 = randn(M,Nt);
lambda = randn(1,Nt);
B = randn(M,Nt);
result = zeros(2,Nt);
tic
est = zeros(M,Nt);
for i= 1:Nt
A = [a1(:,1) a2(:,1)];
result(:,i) = (A'*A + lambda(1,i)*[0 1;0 1])\(A'*B(:,i));
est(:,i) = a1(:,i)*result(1,i)+a2(:,i)*result(2,i);
end
toc
Accepted Answer
More Answers (0)
Categories
Find more on Matrix Indexing 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!