Add operation is too slow
Show older comments
Hi! I have some operation of summing two arrays (vd, bd) of different lengths ((vl + 1)^2 and ((bd + 1)^2). I can't do summing as d = vd + bd (error: different lengths). How can I do this operations faster? I compile MEX, but this did not give the required increase in speed. I need speed up adding because it using around 20 million
function [l, d] = add(vl, vd, bl, bd, lmax)
l = max([vl, bl, lmax]);
d = zeros((l + 1)^2, 1);
i = 1:(vl + 1)^2;
j = 1:(bl + 1)^2;
d(i) = d(i) + vd(i);
d(j) = d(j) + bd(j);
end
2 Comments
KALYAN ACHARJYA
on 27 May 2021
Can you share the detail example? What would be the result in the following case?
vd=[1 2 3]
bd=[4 5 6 7]
Igor Arkhandeev
on 27 May 2021
Accepted Answer
More Answers (1)
vd=[1 2 3];
bd=[4 5 6 7];
N=max(numel(vd), numel(bd));
vd(end+1:N)=0;
bd(end+1:N)=0;
d=vd+bd
Categories
Find more on Write C Functions Callable from MATLAB (MEX Files) 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!