Indexing through arrray in simulink with a for iterator

6 vues (au cours des 30 derniers jours)
Greg Anderson
Greg Anderson le 18 Jan 2021
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'.

Réponses (2)

prabhat kumar sharma
prabhat kumar sharma le 6 Mai 2024
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 le 6 Mai 2024

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 commentaire
prabhat kumar sharma
prabhat kumar sharma le 6 Mai 2024
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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Simulink Functions dans Help Center et File Exchange

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by