Indexing through arrray in simulink with a for iterator

6 次查看(过去 30 天)
I am trying to index through 1x339 workspace variables (not time based just tables of data) in simulink, perform a mathimatical operation and then return the index that satisfies that condition. I continue to get an error related to time base. Is there something I need to setup dfferently in my selector, from workspace blocks, or my workspace variable?
'DepthArray/For Iterator Subsystem/For Iterator Subsystem/From Workspace' has sample time 0. Only constant (inf) or inherited (-1) sample times are allowed in iterator subsystem 'DepthArray/For Iterator Subsystem/For Iterator Subsystem'.

回答(2 个)

prabhat kumar sharma
Hi Greg,
The error message you're encountering is indicating that the From Workspace block within an iterator subsystem is expecting data with a sample time that is either constant (inf) or inherited (-1), but the block is configured with a sample time of 0, which implies a continuous sample time. In an iterator subsystem, which executes based on iterations rather than time, continuous sampling doesn't make sense.
Here are steps you can follow to resolve this issue:
1. Adjust Sample Time in From Workspace Block
  • Double-click on the From Workspace block.
  • Look for the Sample time parameter.
  • Change it from 0 (continuous) to -1 (inherited) or specify a discrete sample time that matches the configuration of your subsystem, though -1 is typically what you'd use in an iterator subsystem since it lets the subsystem control the execution timing.
2. Use a Constant Block for Non-Time-Based Data
If your data is not time-based and you just need to index through tables of data, consider whether you need to use the From Workspace block at all. For static or non-time-varying data:
  • Use a Constant block where you can specify the variable name directly. This block inherently has no issues with sample times in an iterator subsystem.
  • Ensure the data is formatted appropriately in MATLAB Workspace to be used directly.
3. Configure the Iterator Subsystem Correctly
  • Make sure your For Iterator subsystem is set up correctly to iterate over the indices you're interested in. The For Iterator block inside the subsystem should be configured with the appropriate start, step, and end values.
  • The operation you perform inside the subsystem will need to be designed to handle indexing through your data correctly, based on the iterator index.
I hope it helps to resolve your issue!

Walter Roberson
Walter Roberson 2024-5-6

The output of From Workspace is a sampled signal, sampled at the current time. The output of From Workspace is not an array (unless the object in the workspace happens to have more than two columns)

  1 个评论
prabhat kumar sharma
Okay, Is it possible If possible, preprocess your data in MATLAB to convert it into a format that can be iteratively processed in Simulink. This might involve creating a timeseries object with dummy time data if you must use From Workspace and Consider using a MATLAB Function block to programmatically access and process your workspace data based on the iteration index. This approach allows more flexibility for non-time-based operations but requires your data to be accessible in a way that the MATLAB Function block can work with it.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Simulink Functions 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by