How can you create an array from portions of two other arrays using indexing or other methods?

2 views (last 30 days)
Question: I want to create an array based q_mod (14400x11) that draws its values from two other arrays of the same size (q and q_exp) using indexing or some other appropriate mechanism. I have two separate vectors (qhdtp and qexpb, both 1 x 11) that have element values in corresponding columns that sum to the desired length(q_mod).
My desired q_mod array would consist of the values in q(1:qhdtp) and q_exp(qhdtp+1:end) for each respective column, and would be a 14400x11 array. My ultimate goal here is to select the data from the hyperbolic decline function until the slope of the function reaches a certain threshold, after which I will decline the function will become exponential.
I have included my code below and attached the m file for your convenience.
Note: I believe there may be a better way to utilize the logical/dummy array I created (qhdtpcum) to select the values for q_mod. I used this variable to calculate the values for q_exp, but have been unable to figure out how to use this to to create my desired q_mod array.
Code:
%%%Function hyperdecline defined:
%%%function q = hyperdecline(qi,B,di,T)
%%%q = qi*(1+B.*di.*T).^(-1./B);
qi = 20000;
y=40;
di=.01;
b=1:0.1:2;
n=y*360-1;
m=30;
t = 0:n;
qab=500;
dt=.05;
dhm = .05;
% Hyperbolic Curve Calculations
[T B] = ndgrid(t,b); % Create grid of t and b values to iterate over
q = hyperdecline(qi,B,di,T);
qcum = cumsum(q);
qm = squeeze(sum(reshape(q',size(b,2),m,[]),2))'; % Aggregate q into 30 day months
% Sequential change Calculations
qchg=diff(q)./q(1:end-1,:)*360; %Calculate sequential change between elements in columns. Use diff(q) then divide element wise for first element through second to last element
qhdt = qchg>-dhm; qhdt = [zeros(1,size(qhdt,2)); qhdt]; % Calculate dummy variables at point where decline is less < than minimum hyperbolic decline (dhm)
qhdtp = n-sum(qhdt)+1; % Calculate last point of hyperbolic decline
qexpb = sum(qhdt); % Calculate beginning t (day) of expoential decline
qhdtpcum = cumsum(qhdt); % Calculate cumulative days on exponential decline (past hyperbolic decline)
%Exponential Curve Calculations: q_exp = q(at last day of hyperbolic decline)*exp(-dt/360*qhdtpcum)
q_exp_start = q(qhdtp);
[qhdtp_gridded] = ndgrid(q_exp_start,1:n+1)';
q_exp = qhdtp_gridded.*exp(-dt/360*qhdtpcum);
%Create modified/mixed hyperbolic and exponential curve
% qmod --> where for n=1:qhdtp, qmod = q & for n=qhdtp:n, qmod = q_exp

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!