How to continually clock in data during a simulation within Simulink

Hi,
I am experimenting within Simulink, and I wish to be able to run a simulation while clocking in input data several times during the simulation. I though to use a selector block and a counter limited block, however I keep getting run-time errors which identify a range problem with the idx input on the selector. I have set the Starting index (port) option in the selector and also set the input port size to 1, but the error says it is not in the permissable range (0 through 0).
I'm a bit confused with the error, and I am hoping it could be further explained. Further guidance would be appreciated.
I have attached a capture of my test with the parameters and the error for context.
Regards.

回答(3 个)

Hi Dan,
To resolve this issue, you have to create a new Simulink model named 'Simulink_Selector_Counter_Limited'. Then, add a Selector block to the model and sets the starting index of the Selector block to 1 using set_param. Also, add a Counter Limited block to the model, it should be connected to the input of the Selector block using add_line. Set the simulation time to 10 seconds, and the model is simulated using sim.
% Create a Simulink model with a Selector block and a Counter Limited block model = 'Simulink_Selector_Counter_Limited'; open_system(new_system(model));
% Add Selector block add_block('built-in/Selector', [model '/Selector']); set_param([model '/Selector'], 'StartingIndex', '1');
% Add Counter Limited block add_block('built-in/Counter Limited', [model '/Counter Limited']);
% Connect blocks add_line(model, 'Counter Limited/1', 'Selector/1');
% Set simulation parameters simTime = 10; sim(model);
This approach should help in resolving the runtime errors related to the range problem with the idx input on the Selector block. Feel free to adjust the simulation parameters and block settings as needed for your specific simulation requirements.

1 个评论

Hi Umar,
Thanks for your reply. Unfortunatley this did not work. When I ran the script, I received the error that the Selector block does not have the Starting Index parameter.
After that I looked at what the parameter was called which is 'IndexOptionArray', and tried to set the parameter directly, however I obtained the same error as I did with my initial question with the only difference being that the range was now (1 through 1).
I also tried to add the parameters to your intial script, but this resulted in the same error I saw with your script which was related to not having the index parameter.
set_param([model '/Selector'], '{Select all | Index vector (dialog) | Index option (port) | Starting index (dialog) | Starting index (port) | Starting and ending indices (port)}','Starting index (port)');
I have aded all three errors that I just described to the code below.
I cannot explain why the parameters cannot be found, but considering when I tried to set the parameters directly via the command window, and received a similar issue to what the origianl question was related to, I'm wondering if what I wish to do is even possible?
Intrested to hear your feedback.
>> simModelSelCtrBlocks
Error using simModelSelCtrBlocks
Selector block does not have a parameter named 'StartingIndex'
>> set_param(Simulink_Selector_Counter_Limited/Selector,'IndexOptionArray','Starting index (port)','1')
Error while initializing parameters.
Caused by:
Element 1 of input port <Idx1> in 'Simulink_Selector_Counter_Limited/Selector' has a value of 0. This value is not within the range of permissible values (1 through 1) that allows
selection of a valid input data element
>> simModelSelCtrBlocks
Error using simModelSelCtrBlocks
Selector block does not have a parameter named '{Select all | Index vector (dialog) | Index option (port) | Starting index (dialog) | Starting index (port) | Starting and ending indices (port)}'

请先登录,再进行评论。

No problem, Dan. I do understand that you are facing difficulties and sometimes it causes frustration when reliable solution is not found. However, I did some research and trying to help you follow these tips to resolve your issues.

Troubleshooting Parameter Settings in Simulink Blocks

When dealing with parameter settings in Simulink blocks, especially in complex scenarios, ensuring accuracy is paramount to avoid errors. Let's address common issues and explore effective solutions.

*Error 1: 'Selector block does not have a parameter named 'StartingIndex'*

The error indicates that the parameter 'StartingIndex' isn't recognized by the Selector block. This typically happens due to a typo or incorrect parameter name. To resolve this, verify the exact parameter name expected by the Selector block. Using the precise name defined by the block is crucial to prevent such errors.

 **Error 2: 'Element 1 of input port <Idx1> has a value of 0...'**  

This error points to an issue with the input values provided to the Selector block. The message indicates that the value is outside the expected range (1 through 1), possibly due to incorrect indexing or data type mismatch. Ensure that input values align with the specified range and data type to fix this issue.

 **Error 3: Parameter Setting via Command Window**  

Attempting to set parameters via the command window resulted in an error related to parameter names. This suggests that the parameter name used in the command doesn't match the expected name for the block. Double-check the parameter names and syntax during command-based parameter settings to avoid such discrepancies.

*Feasibility and Troubleshooting Tips*

Given the complexities in setting parameters for the Selector block, consult the block's documentation to confirm accurate parameter names and values. Ensure accessibility and modifiability of block properties through preferred methods.

*Troubleshooting Steps:*

1. *Verify Parameter Names and Values:* Confirm exact parameter names and expected values specified by the Selector block.

2. *Check for Typos and Syntax Errors:* Review parameter-setting commands for any typos or syntax errors that could lead to issues.

3. *Validate Input Values:* Ensure input values provided to the block are valid and within the specified range and data type.

4. *Explore Different Setting Approaches:* Experiment with various methods like Simulink interface or script commands to set parameters effectively.

By meticulously addressing parameter settings and resolving discrepancies, successful configuration of the Selector block can be achieved. Your dedication to troubleshooting is commendable, and with systematic approaches, reaching your desired outcomes becomes feasible. For further assistance tailored to your specific challenges, feel free to provide additional details.

Hi Dan,
It appears that the output of the Bit to Integer Conversion block is a scalar, which can be checked by going to Debug -> Information Overlays -> Signal Dimensions, or Debug -> Information Overlays -> NonScalar Signals
If that is, in fact, the case, there will be a problem when the counter reaches 1 because the U only has one element,and, therefore, U(Idx1) = U(1) is invalid because zero-based indexing is selected.
I'm not sure exactly what the intent of the model is, so can't suggest any modifications. Can you provide more detail on what you want to happen each time the counter increments?

6 个评论

Hi Paul,
I had tried both of the settings you mentioned within the information overlays, however I do no receive any value on the output to confirm it is a scalar which is a little frustrating.
Also note, that when trying these settings, the output of the constant block has been set to uint8, which made me think I should see 1x8 on the output, yet it is only 8.
I have also tried to set the Index mode to One-based, but I receive the error
Element 1 of input port <Idx1> in 'Model name/Selector' has a value of 0. This value is not within the range of permissable values (1 through 1).
What I am trying to do is use the counter limited block as a clock. Every 50 counts, I would like to clock in the 1x8 data vector. I would like to do this several times during a simulation run, as opposed to have it constantly there for the entire simulation. This will allow me to change the data during simulation.
Do you beleive this can be achieved with the current blocks?
Or will this error always occur based on the permissable values with either index mode being set?
If nothing on the display changes on that signal when setting those information overlays, then the output of the Bit to Integer Conversion block is a scalar.
The data type of the Constant block (uint8) has nothing to with the size of the of the output. The indication of 8 means the that signal has eight elements, which Simulink calls a "1-D" signal. If you'd rather it be 1x8, uncheck "Interpret vector parameters as 1-D" in the Constant block. There is anothr Information Overlay to display the type of a signal if you need to see that.
If changing the index mode on the Selector to one-based, then there will be an error when the Idx1 input is 0, as you reported, and there would also be an error if the Idx1 input is 2 (and 3, etc.).
The Selector block is typically used to select a subset of elements from a signal that has more than one element. Is that the functionality that's needed for this application? In other words, having a scalar input (U) to the Selector block isn't really useful. I suspect, but could be wrong, that you're trying to use the Selector block for some sort of time-based concept, but that's not what the block is for.
I'm afraid I still don't understand what "clock in the 1x8 data vector" means? Is the 8 element vector not really a Constant in the actual Simulation? If not, what governs how and when that 8 element vector actually changes?
If you have an 8-element vector that's supposed to change as function of time, one would typically implement that function using Simulink blocks. If that vector changes at a fixed time step, then the Sample Time parameter on those blocks would be used to specify that step.
Hi Paul,
Thanks for the reply.
Based on what I experienced and your feedback, I don't think the selector block was the correct it em to use.
To answer your questions;
Is the 8 element vector not really a Constant in the actual Simulation? Yes it is, however I wanted to output it as 1x8 data vector.
If not, what governs how and when that 8 element vector actually changes? The question of how was what my original question was about, but I wanted it to occur every every 10ms for a simulation period of 100ms.
What I did was use a counter as a trigger, and put the 1x8 vector in a trigerred subsystem, so thay it would only output the vector contents when triggerred.
Does that make sense? That's what I meant buy 'Clock in/out'.
I was hoping there may be a more elegant way.
When the triggered subsystem is triggered, it outputs an 8-element vector?
Does the output from the triggered subsystem change on every trigger event?
If so, is the new ouput determined dynamically as the simulation executes? Or is the sequence of outputs known before the simulation starts and stored in a data structure, such as an n x 8 array in the base workspace, and you want to sequence through that structure at a 10 ms sample rate?
Hi Paul,
No the output is not determined dynamically it remains the same.
So, the n x 8 array is stored within the Simulink model as a constant block with the data type set applicably.
But yes, the idea is to treat them as 1 byte and seqeunce the byte every 10 ms.
Option 1. Use the From Workspace. Make sure to review all of the block parameters, especially the "Interpolate Data" parameter.
Option 2. Use 1D Lookup Table block. Make sure to review all of the block parameters, especially the "Interpolation Method" and "Extraploation Method" parameters.

请先登录,再进行评论。

类别

产品

版本

R2023b

提问:

2024-7-4

评论:

2024-7-24

Community Treasure Hunt

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

Start Hunting!

Translated by