Problem with number of inputs and outputs
조회 수: 21 (최근 30일)
이전 댓글 표시
Hi everyone, I have just a little question about inputs and output.
First of all, the thing that I want to do is to put as input of an generic engine a variable that change for every second of the simulation (variable from Matlab workspace).
So I put a "From workspace" block and it has 2395 outputs, so of course it cannot connect to a simulink - PS converter that have only one input port.
That's why I'm asking how can I do this.
Thanks in advance for the reply !
댓글 수: 0
채택된 답변
Sara Nadeau
2023년 7월 6일
What is the type and format of your input data? What type of output do you expect from the From Workspace block?
The From Workspace block supports several formats of input data. In general, creating a timeseries object works for most workflows and provides consistency with the format for most logged data as well.
Here is the reference page for the From Workspace block: https://www.mathworks.com/help/simulink/slref/fromworkspace.html
And here is an example that shows code examples for getting numeric vectors into each supported format: https://www.mathworks.com/help/simulink/ug/load-data-using-the-from-workspace-block.html
I hope these doc links are helpful. If you have more questions or could provide more information about exactly how you configured the block and formatted the data in a way that resulted in this form of output, I might be able to give a more specific answer.
댓글 수: 3
Sara Nadeau
2023년 7월 7일
편집: Sara Nadeau
2023년 7월 7일
So you have said that the output has 2395 elements, and you don't think that is correct.
What are the dimensions of the output with 2395 elements? 1x2395? Something else?
I am less familiar with the Signal Builder block so considering the From Workspace block again - how did you specify the Data parameter that resulted in the output with 2395 elements?
Based on the description about wanting the output at 34s to be the 34 point in the list, I can describe a way to get this out of the From Workspace block, but I can't promise it will be exactly what you need.
When you use the structure without time format, you can specify input values for the From Workspace block to load each time it executes without specifying time values that correspond to each input value. To associate the value with simulation time, you then specify the sample time for the From Workspace block and disable linear interpolation. You said that you want the 34th value in the list to be the output for 34 seconds, which would imply a sample time of 1 second.
This code would create the variable simin using the structure without time format. The data just counts from 0 to 34. The call to set_param sets the sample time for the From Workspace block to 1 second and disables interpolation.
data = 0:34;
simin.signals.values = data;
simin.signals.dimensions = 1;
simin.time = [];
set_param("mymodel/From Workspace","SampleTime","1","Interpolate","off")
In simulation, this From Workspace block loads one value from the specified input data every 1 second of simulation time.
This page of the documentation shows another example that includes code and a model to see how this works: https://www.mathworks.com/help/simulink/ug/specify-how-to-load-simulation-input-data.html#mw_6c72ce30-a717-48eb-989c-cbb1d0e154b4
추가 답변 (1개)
Aniketh
2023년 7월 5일
To connect multiple outputs from a "From Workspace" block to a single input port of a Simulink block, you can use a "Bus Creator" block. The "Bus Creator" block allows you to combine multiple signals into a bus signal, which can then be connected to a single input port.
Here's how you can connect multiple outputs from the "From Workspace" block to a single input port using a "Bus Creator" block:
- Place a "From Workspace" block in your Simulink model.
- Specify the variable name and the sample time for the "From Workspace" block to retrieve the data.
- Right-click on the "From Workspace" block and select "Outputs > Add Output". Repeat this step for each output you want to have.
- Place a "Bus Creator" block in your Simulink model. You can find it in the "Simulink/Signal Routing" library.
- Open the "Bus Creator" block by double-clicking on it.
- In the "Bus Creator" dialog box, click on the "+" button to add a new bus element for each output from the "From Workspace" block.
- Give each bus element a name and specify its data type and dimensions to match the corresponding output from the "From Workspace" block.
- Connect the outputs of the "From Workspace" block to the corresponding bus elements in the "Bus Creator" block.
- Connect the output of the "Bus Creator" block to the input port of the Simulink block that requires the multiple inputs.
By following these steps, you can combine the multiple outputs from the "From Workspace" block into a bus signal using the "Bus Creator" block. This bus signal can then be connected to a single input port in your Simulink model.
참고 항목
카테고리
Help Center 및 File Exchange에서 Troubleshooting에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!