[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Request help speeding up script
From: |
Rob Teasdale |
Subject: |
Request help speeding up script |
Date: |
Mon, 25 Jun 2007 14:23:54 -0700 (PDT) |
Hi all,
I am still learning Octave, and I am still discovering new ways of optimising
code. I have managed to vectorise a lot of my 'for' loops, and I have managed
to speed my small script up dramatically, although I am having trouble with
this last code snippet below. What I am trying to achieve is to calculate the
area of a quadrilateral by the vector cross product of its diagonals. X, Y and
Z contain the points that describe my mesh. I am sure that there is a way to
vectorise at least part of this, and I would really appreciate any suggestions,
[R C] = size(X); % all matrices the same size
row = 0;
for i = 1:(R-1)
for j = 1:(C-1)
P4 = [X(i,j) Y(i,j) Z(i,j)];
P3 = [X(i,j+1) Y(i,j+1) Z(i,j+1)];
P2 = [X(i+1,j+1) Y(i+1,j+1) Z(i+1,j+1)];
P1 = [X(i+1,j) Y(i+1,j) Z(i+1,j)];
p = P2-P4;
q = P3-P1;
row++
r(row,:) = 0.5 * (cross(p,q)); % calculate the area
endfor
endfor
Thanks in advance
Rob
____________________________________________________________________________________
Yahoo!7 Mail has just got even bigger and better with unlimited storage on all
webmail accounts.
http://au.docs.yahoo.com/mail/unlimitedstorage.html
- Request help speeding up script,
Rob Teasdale <=