Matrix Referencing

I have a Matrix defined as follows:

wvp =

I want to interpolate within this 2D array, which I start to do with
the following equation:

m = (wvp[i,2]-wvp[i-1,2])/(wvp[i,1]-wvp[i-1,1])

This is readily done in C, but Ruby does not like the fact that I
subtract a one from the index i within the context of the array, i.e.,
[i-1,2]. Even if I try to fake it out by first declaring j = i - 1, and
using j in place of the i-1 within the array coordinate, I get the
following error:

humidity_correction': undefined method-’ for nil:NilClass

It’s claiming my method - is undefined. How do I defeat this?

It’s claiming my method - is undefined. How do I defeat this?
“undefined method `-’ for nil:NilClass” means that the operand to the
left of one of the ‘-’ operators is Nil. That will most likely be one
of the wvp[…] accesses, assuming i and j are initialized correctly.

Check each of
wvp[i,2], wvp[i-1,2], wvp[i,1], and wvp[i-1,1] and see what they return.


Oops you are correct! MATLAB which I wrote the template code in has a
starting index 1, while Ruby has starting index 0. I overran my index.

I told myself in the beginning I had to be wary of this and I just fell
into the trap.