large 3D Matrix calculation
Show older comments
Hi All I have two large matrix and I want to calculate an expression without for loop. this expression is something like matrix d as below
f=[f1 f2 f3]
r=[r1 r2 r3]
d=[f1-r1 f2-r1 f3-r1
f1-r2 f2-r2 f3-r2
f1-r3 f2-r2 f3-r3]
can any one help me?! consider that size(f)=1*1*400 and size(r)=50*50*900 and fii=f(1,1,ii) and rjj=r(:,:,jj)
Accepted Answer
More Answers (2)
f = [f1,f2,f3];
r = [r1,r2,r3];
d = bsxfun(@minus,f,r.');
bsxfun calculates the output without requiring large intermediate arrays (eg using repmat). Although, depending on the size of d, you might still run out of memory...
3 Comments
John D'Errico
on 20 Jan 2015
The heartache of those who write code - shifting specs. The correct answer to the question asked but not the question intended. :)
Categories
Find more on Loops and Conditional Statements 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!