0

I have a function which has discrete time step ,discrete length from origin . These two give height of the function. For example at time 1.2sec , and length 5.5cm from origin height is 10cm. The step size of time is 0.4sec and length step size is 0.5cm. How to store this, I cannot use 2D array with time and length as indexes because those are floating point numbers , which is best method to store this kind of data?

0
0

I cannot use 2D array with time and length as indexes because those are floating point numbers

Since you're using discrete time [and length] step[s] with fixed step sizes 0.4sec and 0.5cm, you actually can use an integer-indexed array. For f(i,j), i~time, j~length, just calculate time = time0 + i*dt, where time0=0 (or any origin you like), and dt=0.4 (as per your post). And similarly for the length dimension. And note that both functions are easily invertible in case you need to find the indices corresponding to a given time,length (you also might want to write an interpolation function between i,j points).

2
  • what if the step size is unknown! , is the hash only one that can be used to store ? Oct 23 '20 at 4:08
  • @MokkaNaresh By "unknown" I assume you mean "not easily computable", i.e., just a bunch of (time,length,height) triples that are input. Then I'm not sure about "only"; not sure about "best", either. Lots of approaches you could program, depending on the exigencies of the situation, e.g., how much input there is, how frequently you have to access it, etc. Not too much input that's accessed frequently might suggest a different approach than lots of input accessed only a few hundred thousand times. Oct 24 '20 at 7:40

This site is temporarily in read only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .