3D table lookup and Saving

Hey friends,

I'm trying to figure the best approach to a 3D table for lookup.
This table must be able to be updated with values as well.

Basically a fuel table for cars

So for example

MAP TABLE
RPM 1 ** 2** **3 **
1000 2.3 2.5 3.9
**2000 ** 3.3 3.9 4.5
**3000 ** 3.9 4.4 5.5

Then when i figure 2000 RPM and a map of 2, i should be able to get the 3.9 value

How do they do this?

That is a 2D table. One approach is to use a 2D array to store it, as follows.

#define ROWS 3
#define COLUMNS 3

float table[ROWS][COLUMNS]= {
   {2.3, 2.5, 3.9},
   {3.3, 3.9, 4.5},
   {3.9, 4.4, 5.5}
   };

See Multidimensional Arrays in C - GeeksforGeeks

Indexing that table requires some transformations, for example to extract the entry at rpm=2000 and map=2 you could write:

int map=2,rpm=2000;
float value = table[map - 1][rpm/1000 - 1];

Well, that's nice way to do it.

I thought it was a 3D table No, that was a 3D table because of RPM vs MAP vs Value
thanks for the correction

But then, how could I update the values?

donperry:
Well, that's nice way to do it.

I thought it was a 3D table No, that was a 3D table because of RPM vs MAP vs Value
thanks for the correction

But then, how could I update the values?

The third dimension of that table would be the individual digits of each number you show.

Paul

But then, how could I update the values?

Take a look at the very helpful link I posted.

Thanks jremington, Paul,

Yes, I realize now that that the "3rd" would be the actual values.

The table stores only values at certain indices (at the moment, rpm=1000,2000, 3000, map=1,2,3, before transformation to array indices). You can expand that, of course, but you can also estimate values in between the indices.

For example, from the existing entries, it is possible to estimate the table value for rpm=2500 and map = 2.5. One method is called bilinear interpolation, described here.