Matrix Referencing

I have a Matrix defined as follows:

wvp =
Matrix[[-40.0,0.006],[0.0,0.045],[32.0,0.18],[59.0,0.50],[70.0,0.74],
[100.0,1.93],[130.0,4.53]]

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:

C:\rails_projects\TestRubyConcepts\lib\main.rb:74:in
humidity_correction': undefined method-’ for nil:NilClass
(NoMethodError)

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.

Nathan

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.

Thanks