Question

Let's say I have a data table that is 1x15

 [21 78 33 59 90 26 88 54 36 63 72 37 48 93 56]

So for my streaking equation I need to implement this:

% Streaking = {[abs(Q_n - ((Q_n-1 + Q_n+1)/2))] / ((Q_n-1 + Q_n+1)/2)))}*100

Explanation of the Equation:

Let's assign the value 90 to Q_n (this comes from cell (1,5)) Using this value would mean that for Q_n-1 we'd want the value 59 and for Q_n+1 we'd want the value 26 (so in essence the cell before (1,4) and the cell after (1,6))

Q_n = 90

Q_n-1 = 59

Q_n+1 = 26

My question is: How would I do this for the entire data set and apply them to the streaking equation? (excluding row 1 and 15 as you cant have a Q_n-1 for row 1 and you cant have a Q_n+1 for row 15)

I was thinking of something maybe along the lines of this:

Q_n = 1;
while Q_n < length(middle.middle_interpolate)
    Q_n = Q_n+1;
    before = middle.middle_interpolate{Q_n-1};
    actual = middle.middle_interpolate{Q_n};
    after = middle.middle_interpolate{Q_n+1};
    averg = ((before + after)/2);
    equation = (abs(actual-averg)/averg)*100;
    plot(equation);
end
Was it helpful?

Solution

I broke this out into parts so you could see what I was doing. It also only works for this particular dataset since the indicies are hardcoded (but I bet you can figure out how to make it work for any dataset you have).

averg = mean([Qn(1:13),Qn(3:15)],2); % this is just getting your averg value.
actual = Qn(2:14);
equation = abs(actual-averg)./averg*100;
plot(equation)

Of course you could put this all on one line and make it look crazy complicated...

equation = abs(mean([Qn(1:13),Qn(3:15)],2) - Qn(2:14))./mean([Qn(1:13),Qn(3:15)],2)*100

But you want to keep it somewhat readable for others who might look at the code in the future.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top