Need help with a nested for loop
Show older comments
I have
L = 28x1 vector
D = 28x1 vector
My equation is: V = L*((pi*((D+0.064).^2)/4)-(pi*D.^2)/4)
I have tried
for n = 1:length(D1)
for m = 1:length(L1)
TankVol(n,m) = L1(m,:)*((pi*((D1(n,:)+0.064).^2)/4)-(pi*D1(n,:).^2)/4);
end
end
But it's not giving what I need
It's going through the loop too many times if that makes sense, I basically need a V value for each value in L and D.
Accepted Answer
More Answers (2)
Murali Krishna
on 30 May 2015
In matlab u need not use loop to access each element. Try this
V = L.*((pi*((D+0.064).^2)/4)-(pi*D.^2)/4)
result will be stored in v as column matrix
Walter Roberson
on 30 May 2015
t = ((pi*((D+0.064).^2)/4)-(pi*D.^2)/4);
V = bsxfun(@times, L, t.');
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!