matlab中reset,Reset the read position

Create a matlab.io.datastore.sdidatastore for a Signal

Simulate the sldemo_fuelsys model, which is configured to log several signals, to create data in the Simulation Data Inspector repository.

sim('sldemo_fuelsys')

Use the Simulation Data Inspector programmatic interface to get the signal ID for the signal.

runCount = Simulink.sdi.getRunCount;

latestRunID = Simulink.sdi.getRunIDByIndex(runCount);

latestRun = Simulink.sdi.getRun(latestRunID);

speedSigID = latestRun.getSignalIDByIndex(4);

Use the signal ID to create a matlab.io.datastore.sdidatastore for the speed signal.

speedSDIds = matlab.io.datastore.sdidatastore(speedSigID);

Verify the Contents of the Datastore

Check the Name property of the matlab.io.datastore.sdidatastore to verify that it matches your expectations.

speedSDIds.Name

ans =

'map'

You can also use the preview method to check that the first ten samples in the signal look correct.

speedSDIds.preview

ans=10×1 timetable

Time Data

______________ _______

0 sec 0.589

0.00056199 sec 0.58772

0.0033719 sec 0.58148

0.01 sec 0.56765

0.02 sec 0.54897

0.03 sec 0.53264

0.04 sec 0.51837

0.05 sec 0.50594

0.055328 sec 0.5

0.055328 sec 0.5

Process Signal Data with the matlab.io.datastore.sdidatastore

When your signal is too large to fit into memory, you can use the readData method to read chunks of data from the Simulation Data Inspector repository to incrementally process your data. Use the hasdata method as the condition for a while loop to incrementally process the whole signal. For example, find the maximum signal value.

latestMax = [];

while speedSDIds.hasdata

speedChunk = speedSDIds.read;

speedChunkData = speedChunk.Data;

latestMax = max([speedChunkData; latestMax]);

end

latestMax

latestMax = 0.8897

On each read operation, the read method updates the read position for the start of the next read operation. After reading some or all of the matlab.io.datastore.sdidatastore, you can reset the read position to start again from the beginning of the signal.

speedSDIds.reset

Process Signal Data in Memory

When the signal referenced by your matlab.io.datastore.sdidatastore fits into memory, you can use the readall method to read all the signal data into memory for processing, rather than reading and processing the data incrementally with the read method. The readall method returns a timetable with all the signal data.

speedTimetable = speedSDIds.readall;

speedMax = max(speedTimetable.Data)

speedMax = 0.8897

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值