# how can I do this fast addition and multiplication?

1 view (last 30 days)
Kate on 6 Aug 2014
Edited: Kate on 6 Aug 2014
Hi all,
I am transforming some data using an equation that involves a multiplication and addition. (Please see line 20 in the full code below this post., i.e. the following line:
newdata1 = (((R)*X1_full(:,i))+ T)';
In this example, I only have 4 data points (i.e. in the 'X1_full' variable). So speed is not a problem using the FOR loop. However, my actual dataset is very large (2 million data points). Any suggestion to improve the speed will be helpful.
cheers. K.
clc;clear all;close all
% input data to transform
X1_full = [1 2 3 5;
45 8 7 95;
12 78 98 3]
% R and T are transform params
T = [292.213040777858;78.1087497964877;865.7398878749]
R=[0.999998463087434,8.08983068375718e-05,-0.00175136467802407;
-8.44379283493625e-05,0.999997954040306,-0.00202108521267277;
0.00175119759243091,0.00202122998804671,0.999996423961770;]
% Loop through all data and transform
for i = 1:size(X1_full,2)
% Formula to transform the input data
newdata1 = (((R)*X1_full(:,i))+ T)';
Savenewdata1(i,:) = newdata1
end

Michael Haderlein on 6 Aug 2014
Savenewdata1=bsxfun(@plus,(R*X1_full),T)';
Kate on 6 Aug 2014
Edited: Kate on 6 Aug 2014
thank you Michael.