how can I do this fast addition and multiplication?
2 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Michael Haderlein
2014-8-6
Savenewdata1=bsxfun(@plus,(R*X1_full),T)';
can replace your loop and should be faster than your solution.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Mathematics and Optimization 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!