Typecast for int in Octave / Matlab

I need to call the index of a matrix created using the linspace command, and based on some data taken from an oscilloscope. Because of this, the data entered is double. However, I cannot name:

Time[V0Found]

where V0Found is something like 5.2, however, index 5 is pretty close, so I need to drop the decimal number. I used this equation to remove the decimal:

V0FoundDec = V0Found - mod(V0Found,1)
Time[V0FoundDec]

However, even though it reduces the decimal, the octave still complains about it.

So what can I do to cast it to int?

+3
source share
3 answers

MATLAB int8(x) int16(x) .

, .

myarray(floor(indexlist))

myarray(round(indexlist))

myarray - , indexlist - noninteger.


:

octave-3.2.3:8> v=rand(1,8)*10+1
v =

   3.1769   1.4397   8.7504   1.7424   6.9413   3.1663   8.4085   9.0179

octave-3.2.3:9> a = (1:1:20).^2
a =

 Columns 1 through 15:

     1     4     9    16    25    36    49    64    81   100   121   144   169   196   225

 Columns 16 through 20:

   256   289   324   361   400

octave-3.2.3:10> a(floor(v))
ans =

    9    1   64    1   36    9   64   81
+5

round, floor, ceil .

, , :

V0FoundDec = round(V0Found);
Time(V0FoundDec) % not Time[V0FoundDec]

+2

Matlab - interp1 . :

yout = interp1 (xdata, ydata, xin,...) yout = interp1 (ydata, xin,...) xdata 1: length (ydata)

,

V0FoundDec = ( (V0found))

V0FoundDec = interp1 (, V0found, '')

( )

V0FoundDec = interp1 (, V0found)

V0FoundDec = interp1 (Time, V0found, 'linear')

and you can also extrapolate outside (using "extrap" or provide an extrap value), where

Time (Round (V0found))

will fail if round (V0found) 1 or> length (time)

0
source

Source: https://habr.com/ru/post/1739383/


All Articles