How to continually clock in data during a simulation within Simulink

14 visualizaciones (últimos 30 días)
Dan81
Dan81 el 4 de Jul. de 2024
Comentada: Paul el 24 de Jul. de 2024
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.

Respuestas (3)

Umar
Umar el 4 de Jul. de 2024
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 comentario
Dan81
Dan81 el 5 de Jul. de 2024
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)}'

Iniciar sesión para comentar.


Umar
Umar el 5 de Jul. de 2024

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.


Paul
Paul el 6 de Jul. de 2024
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 comentarios
Dan81
Dan81 el 24 de Jul. de 2024
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.
Paul
Paul el 24 de Jul. de 2024
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.

Iniciar sesión para comentar.

Productos


Versión

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by