필터 지우기
필터 지우기

How to continually clock in data during a simulation within Simulink

조회 수: 28 (최근 30일)
Dan Lardner
Dan Lardner 2024년 7월 4일 14:10
댓글: Paul 대략 3시간 전
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개)

Umar
Umar 2024년 7월 4일 15:24
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
Dan Lardner
Dan Lardner 2024년 7월 5일 2:59
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)}'

댓글을 달려면 로그인하십시오.


Umar
Umar 2024년 7월 5일 4:09

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 2024년 7월 6일 1:38
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?
  댓글 수: 4
Dan Lardner
Dan Lardner 대략 5시간 전
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.
Paul
Paul 대략 3시간 전
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?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 String에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by