Initiate array in Simscape

1 visualizzazione (ultimi 30 giorni)
Zubair Martin
Zubair Martin il 30 Gen 2024
Risposto: Yash il 5 Feb 2024
I have an array in my workspace and would like to initiate the values at a particular time step in Simscape. My current Simscape model has a 'from workspace' block where it cycles through the array (and then repeats). However, I only want to initiate these values at t = 10 rather than t = 0. Is there a way to do this?

Risposte (1)

Yash
Yash il 5 Feb 2024
Hi Zubair,
As I can understand, you want to initialize an array in Simulink only after a specific time has elapsed. There are several approaches you can take, below are some methods you might consider:
1. Prepare the Data in MATLAB Workspace and Configure the "From Workspace" Block accordingly:
  • Ensure that your array in the workspace is formatted as a time series or as a matrix where the first column represents time steps, and the subsequent columns represent the data points.
  • Modify the time data so that the value changes occur at t = 10. For example, if your original data is a matrix data and you want the change to happen at 10 seconds, you might append a row with the initial value at time 9.999 and the new value at time 10.
% Example of modifying data to change at t = 10
initial_value = ...; % Your initial value before t = 10
new_values = ...; % Your array of new values to introduce at t = 10
data = [0, initial_value; % Before t = 10
9.999, initial_value; % Just before the change
10, new_values(1, :); % New values introduced at t = 10
11, new_values(1, :); % Values constant after t = 10
... % Rest of your time-value pairs
];
  • Open the block parameters and ensure that the data is correctly formatted for the block's expectations (e.g., as a structure with time, signals, and possibly dimensions fields, or as a matrix).
  • Make sure the "Interpolate data" option is selected if you want a smooth transition between the data points.
2. Use an Enabled Subsystem:
  • If you want to ensure that the data is not read until t = 10, you can use an Enabled Subsystem that contains the "From Workspace" block.
  • Create an enable signal that becomes true at t = 10. This can be done using a "Step" block with the Step time set to 10 seconds.
  • Connect the enable signal to the Enabled Subsystem.
3. Use the "Step" block:
  • If you want the signal values to become zero before t=10 and and values from workspace after that, you can use a "Step" block.
  • Use a "Product" block with the "Step" block and the 'From Workspace" block as inputs and you will get the desired results.
Hope this helps!

Prodotti


Release

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by