simulink import from workspace without the timestamp?
23 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hey everyone!
I have few questions/issues that I just can't solve by myself.
Below is a wall of text but to simplify my problem:
-If I have a Constant block set to output 1:5:50. How can I convert this to output a time series with sample time of 1 instead of the vector output? Output I need: time = 1, Output = 1; time = 2, Output = 6... Is the vector from the constant block adjustable in that way with other blocks?
I'm building Simulink model that consists of multiple MATLAB Function blocks. The MATLAB Function blocks require many inputs that are either constant (dimensions like size or weight that do not change) and inputs that varies over time (speed, power etc.). Some of the time varying variable inputs are same for every MATLAB Function, for example speed is the same for every MATLAB Function but power or other time varying variables are unique.
The idea is to create a custom Simulink library with "blocks" that are masked so the inputs can be easily changed without much of Simulink experience.
Few questions:
-The data (time varying variables such as speed) is automatically loaded and generated to matlab workspace as Nx1 columns for example with name Speed_1 (around million observations N). To import this variable into simulink I need to add timestamp (1:N) to the first column of Speed_1 as the From Workspace block requires, Speed_1 is now Nx2 type double. Is there a way (other block or something?) to import the Nx1 directly to Simulink? I hoped that constant block would recognize the workspace variable if I inputted the variable Speed_1 instead of a constant.
-It would be beneficial if I could either input the time varying variable Speed_1 or just a constant speed of 100 m/min.
-For the time varying variables that are same for every MATLAB Function I use From Workspace -> GOTO and use FROM block for every MATLAB Function.
I hope my explanation was clear enough :s sorry for my English. I'm glad for all the help and please ask if something was unclear!
TL:DR
How to import Nx1 data into Simulink from workspace? (From Workspace requires the timestamp)
What Simulink block(s) should I use to be able to either input a constant or workspace variable into my MATLAB Function. (From Workspace block doesn't accept integer values and Constant block doesn't accept variables from workspace) Maybe a combination of these two blocks with some kind of IF block ?
0 Commenti
Risposte (1)
Alain Kuchta
il 12 Mag 2017
Creating a Reusable Model
If you want to create a model which is well suited for reuse, you should use Inport and Outport blocks to represent the inputs and outputs of the model. This allows flexibility in determining the source of inputs and destination of outputs.
You can parameterize your model so that constants internal to the model can be adjusted when the model is referenced.
To understand the difference between inputs and parameters, consider the Gain block. The signal to be multiplied by the gain is an input while the quantity of the gain is a parameter. For more information about parameterizing a model, refer to the following documentation:
Importing data from the MATLAB workspace
Assume an Nx2 double matrix A exists in the MATLAB workspace. The From Workspace block will interpret this matrix as N samples of 1x1 double, where the ith sample occurs at time A(i,1) and has value A(i,2).
Simulink simulates the response of a system over time so time stamps are necessary for Simulink to understand how to use the data supplied in A.
Keep in mind that your MATLAB function block will be called once for each time increment of the simulation.
You may also be interested in the 'sim' function which can be called from MATLAB to simulate a Simulink model without opening the Simulink window:
0 Commenti
Vedere anche
Categorie
Scopri di più su Sources in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!