如何让matlab输出指定位置的数据是多少?。

比如t=0:0.01:5
经过运算得到很多离散数据。我想在想知道t=3.1时候,对应的数据,应该怎么找出来?

 Accepted Answer

vevim
vevim on 25 Nov 2022

0 votes

因为 t=0:0.01:5 是经过浮点运算得出的离散数值,这些数值实际上是有浮点误差的,所以,你无法使用 find(t==3.1) 来查找索引。不过你可以用下面的办法索引:
t(round(3.1/0.01)+1)
假设你计算出的对应 t 的数据是 y,那么 y 中对应 t = 3.1 的数据就是:
y(round(3.1/0.01)+1)

More Answers (0)

Tags

Asked:

on 25 Nov 2022

Answered:

on 25 Nov 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!