How to send data to a block continuously, like through clock block in simulink.

5 次查看(过去 30 天)
I am working on traffic simulation in Simulink. trying to show movement using coordinate system i am trying to makeup. I am facing following problem in that.
For now just consider x axis
For translation of car on x axis tried using FOR loop in embedded MATLAB function but it doesn`t give values of intermediate iterations.
When For Subsytem is used it gives out array on N size if N iterations are done.
But the desired Output should be scalar so as to feed it to VRsignal Expander(consider set to 1)
now How can i send values from that N sized array one by one by using another for loop ? n get the same problem again
well i think i m applying wrong Logic to this problem
If there is totally different and simpler way out to solve the problem of sending data continuously. i`ll appreciate the help.

采纳的回答

Paulo Silva
Paulo Silva 2011-1-29
here's a simple way, insert a Constant block in your model, start the simulation from 0 to inf
Now in one m file put a loop with this line of code inside
set_param('MyModelName/Constant','Value',num2str(DataToModel))
Change MyModelName with the name of your model file and DataToModel with the data you want to send, here's a simple example
Make a model with the Constant connected to a Display, run it to inf
Put the next code in one m file and run it
for a=1:0.1:10
set_param('MyModelName/Constant','Value',num2str(a)) %send a to the model
pause(1) %pause for 1 second
end
Now see the value in the display changing
  6 个评论
Piyush
Piyush 2011-1-31
it took long to figure out already known solution.
used Embedded Matlab Function Block(with no output variable) now it is changing the value of Constant Block only..its not coming to Display Sink.
simulation is set to inf.i also tried making subsystem of this loop function. but no use.

请先登录,再进行评论。

更多回答(2 个)

Kaustubha Govind
Kaustubha Govind 2011-1-31
The 'From Workspace' block is specifically designed to allow you to do this sort of thing. (If you have your data in a .mat file, you can use the 'From File' block).
Note that, Simulink needs you to provide time-stamps with your data, so it can determine what data-sample to use at the current time-step.
  2 个评论
Piyush
Piyush 2011-1-31
yes From Workspace block requires timestamps along with data. But i will have no idea at what time the m file is to be called so i cant assume timestamps in advance. also i want to send arguments to the loop in m file
so i m avoiding From Workspace Block.
i Have plans of using Level2 Matlab S-function Block.
Please alert me n guide if u feel I m going in wrong direction.Thnx
Kaustubha Govind
Kaustubha Govind 2011-2-1
In that case, you may find it useful to use the Selector (http://www.mathworks.com/help/toolbox/simulink/slref/selector.html) block in "Index vector (port)" mode, with the "index vector" input as a scalar value sweeping from 1 to N. The Counter Limited (http://www.mathworks.com/help/toolbox/simulink/slref/counterlimited.html) block can be used to generate that kind of sweep.

请先登录,再进行评论。


Erçin
Erçin 2012-1-6
Is there any opposite way send data to M-File with Simulink?

类别

Help CenterFile Exchange 中查找有关 General Applications 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by