在Octave/Matlab中对一个int进行类型转换

Lei*_*sen 3 arrays indexing matlab casting octave

我需要调用使用linspace命令生成的矩阵的索引,并基于从示波器获取的一些数据.因此,输入的数据是双倍的.但是,我真的不能打电话:

Time[V0Found]
Run Code Online (Sandbox Code Playgroud)

其中V0Found类似5.2,但是索引5足够接近,所以我需要删除小数.我使用这个等式来删除小数:

V0FoundDec = V0Found - mod(V0Found,1)
Time[V0FoundDec]
Run Code Online (Sandbox Code Playgroud)

然而,即使减少小数,八度音仍然会抱怨它.

那么,我可以做些什么来将它强制转换为int?

Jas*_*n S 5

在MATLAB中,它应该是int8(x)int16(x)其他整数之一蒙上.

但我很惊讶你需要为索引做到这一点.尝试

myarray(floor(indexlist))
Run Code Online (Sandbox Code Playgroud)

要么

myarray(round(indexlist))
Run Code Online (Sandbox Code Playgroud)

myarray你的数组在哪里,indexlist是你的非整数索引的向量.


例:

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
Run Code Online (Sandbox Code Playgroud)