Vectorize Matrix Formation & Multiplication
2 views (last 30 days)
Show older comments
Fawad Farooq Ashraf
on 17 Nov 2022
Commented: Fawad Farooq Ashraf
on 17 Nov 2022
How can I vectorize the following code
clear;clc
t = 1:10;
v = rand(10,3);
a = rand(10,1);
m = 6:15;
n = 6:15;
M = 1:20;
N = 1:20;
P = ones(20,20);
V = zeros(size(v))';
D = zeros(size(m))';
for i = 1:length(t)
B = [1,0,0;0,cos(a(i)),sin(a(i));0,-sin(a(i)),cos(a(i))];
V(:,i) = B*v(i,:).';
D(i,1) = interp2(M,N,P,m(i),n(i));
end
V = V.'; % (size has to be same as v)
how can I rewrite this code without using loops?
0 Comments
Accepted Answer
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!