[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Help filling an array
From: |
Xierxes |
Subject: |
Help filling an array |
Date: |
Sun, 27 May 2007 08:35:35 -0700 (PDT) |
Hi all,
I have been teaching myself GNU Octave over the last week or so by using an
old MATLAB 5 book, the Octave manual and this mailing list. I have been
trying to develop a function that will calculate the area under a curve at
different locations (I am working with blast waves and need to calculate the
areas under the initial and reflected waves). It is working quite well
except that I cannot fill the final array with results unless I use a for
loop. I am sure it can be done better, and I was hoping that somebody may be
able to assist and point me in the right direction. I have attached a code
snippet below:
% get the min and max limits for trapz
% This bit works as expected - provides the index of the min/max time to
integrate
limits = [indzero(f1(1:end));indzero(f1(1:end)+1)]'
% Calculate the impulse of each phase and store it in the array
% t and p are vectors containing the time and pressure information
respectively
n = length(limits);
imp = [trapz(t(limits(1:end,1):limits(1:end,2)),
p(limits(1:end,1):limits(1:end,2)))]
% This snippet works, but uses a for loop - but I am sure that I can do it
more efficiently
% even though the limits matrix will generally not have more than 10 rows
for i = 1:n
m = limits(i,1); % get the min limit index
mx = limits(i,2); % get the max limit index
imp(i,1) = [trapz(t(m:mx),p(m:mx))];
end
I am enjoying getting back into some coding (and besides is more fun than
writing my thesis :)), and would love to solve this problem (if it is worth
it). Any help would be appreciated,
Cheers
Rob
--
View this message in context:
http://www.nabble.com/Help-filling-an-array-tf3824054.html#a10825771
Sent from the Octave - General mailing list archive at Nabble.com.
- Help filling an array,
Xierxes <=