See if a signal originates from a bus in Simulink - simulink

We have an S-Function that does not support bus signals in Simulink, so programmatically I am trying to find a way to determine if the signal type of an inport/outport originates from/is going to a bus so I can demux and mux the signal automatically as needed. Unfortunately, the only block property I can find that reliably tells if the port comes from or goes to a bus is if it inherits properties from the bus, which might not be true in all cases. Any idea on how to figure this out?

Well, I got an answer back from Matlab support, I have tried this and tested this and it works, the only thing is that Mathworks recommends using a Bus Selector instead of a DEMUX block. In a nutshell, here is what you do:
Find the handles of all signal lines in the model.
Get the names if you need to, however, I did this using handles and it worked fine.
Compile the model to create the 'CompiledBusType' property.
Obtain the 'CompiledBusType' property of each signal line in the model. Then terminate the compilation mode of the model.
'CompiledBusType' returns 'NOT_BUS', 'VIRTUAL_BUS', and 'NON_VIRTUAL_BUS'.
Hope this question helps someone else out, had to wait a week for Matlab to get back to me.

Related

How do I input variables into a Simulink model through MATLAB script (SimDriveline)

For my coursework project in MATLAB, I have decided to build a drive-line model within Simulink, using the SimDriveline toolbox. The idea is to get the user to input values for the various parameters that are associated with each part of the model, such as the engine or the transmission. I would like to able to write this in a MATLAB script, but I'm not sure how to assign the values that are input to the Simulink model. For instance, the stock sdl_vehicle example that comes with SimDriveline. I am aware of the sim() command, but I am still confused on how to use it properly.
Also at the end of the simulation, the program is supposed to display the graphs that are collected in the scope window. I know that in the window itself that the scope can be printed to a figure, but is it possible to print that scope to a figure through MATLAB script?
This is the first time I have ever used a program like MATLAB. I would appreciate any help I could get, many thanks in advance!
There is a simulink block called simin:
http://de.mathworks.com/help/simulink/slref/fromworkspace.html?searchHighlight=simin
I used it some days back and it worked quite well. You can use the block in your model and define some signals/varibles as input.
After that you may write a Matlab-Script with an input function to set all the previous defined input values.

How can I change a Block parameter in Simulink with Serial Port?

I am loading my Simulink Model to a microprocessor. After that I want to change a value of a Block parameter.
In the picture below the data comes to Matlab Function block is coming from Serial Port. Now, appearently th incoming data is assigned to input u of Matlab Function block. In that Matlab Function block I want to write a code that changes , for example, coefficient of s in the Transfer Fcn block. Or it can change any other parameter you can give in code hypothetically.
If anybody can give me any solution that would be ver much appreaciated!. Thank you in advance.
Substitute a custom-made subsystem for the transfer function whose parameters have to change, and create the subsystem from basic blocks so that coefficients can be read from signal sources. You might be interested in this
http://blogs.mathworks.com/seth/2011/03/08/how-do-i-change-a-block-parameter-based-on-the-output-of-another-block/
Even if you don't want to change parameters at every time step, the restriction
"[...] calls to set_param also preclude the model from ever being compiled
into a real-time application."
seems relevant to your case.
Anyway, as far as I know the post linked above still applies in 2014.
Hope that helps.

How to properly propagate multiplex signal names to scope legend via bus system? (Simulink)

I substituted my originial question, the problem is still the same, but the conditions are now different. To review the original question, have a look at the revisions.
I'm looking for a way to interactively select the signals I want to get displayed in my scope Block. The Bus Selector Block with the property Output as Bus does exactly that. I can select all desired signals conveniently without changing any block or signal dimensions.
But the scope block can obviously not handle properly signal names of buses. Therefore my scope legends are wrong:
If I don't set the Output as Bus property and Mux the signal together into the scope block it displays the right signal names. But this is no option as I'd need to adjust the Mux-dimension according to the signals selected.
Are there any workarounds?
(A Floating Scope is no option either)

Simulink memory error in "frame processing mode"

Error:
Cannot propagate frame-based signal through input 'MATLAB Function5' because this input
expects a sample-based signal. The frame-based signal originates from 'mzmzmzcpy/MATLAB
Function5/ SFunction '. Consider inserting an Unbuffer in the signal path.
I am using frame based processing, I save a whole frame in memory and want to read this frame
at the time I need it at the input of same block but every time I get this error, I have tried
both "memory" and "data store memory" blocks, can anybody help me to know how can I change
sampling mode of input as I have tried using "converter" block to change output of "data read
memory" block to frame output even then i found the same error(Cannot propagate frame-based
signal through input 'MATLAB Function5' because this input expects a sample-based signal), then
i tried using buffer but then i found the error given at the beginning of this note.
Have you defined the output(s) of your MATLAB Function block "MATLAB Function5" to be frame-based rather than sample-based? See MATLAB Function Block Editor in the documentation for more details.
EDIT:
If I understand correctly, from your picture, it looks like the problem is with the signal coming out of the memory block. I think memory blocks do not support frame-based signals (or at least, from what I can see in the documentation). As suggested in the comments, try inserting a Signal Specification block before feeding the signal to the MATLAB Function block to enforce a frame-based signal. Failing that, I am not sure, you may want to contact MathWorks for help.

simulink model in matlab

I am working on detecting road lanes using hough transform in simulink(matlab). I have designed the model but its not detecting the lanes. As i am very new to simulink so i have no idea where i am doing the mistake. I tried to upload the model but its not working. I have used the same model as given in matlab-simulink demo except i added a new block of rgb2intensity just after the image from file block and the image which i have given as an input is also uploaded1.Any help???
Without seeing a screenshot of your actual model, it's difficult to give specific detail, but here is some general advice that you may find helpful.
I would debug a Simulink model pretty much the same way that I would debug any other piece of code -- by trying to understand exactly what is happening in my model by examining the output at each step.
For starters, I would make use of the To Workspace block, to see what the data actually looks like at the intermediate stages of your model. This will help you to identify where things are going wrong. For example, what is the output of rgb2intensity? Is this function transforming your data in the way that you expect it to? Ask that question of each block in your model if you have to. If the block is not behaving the way that you expect it to, then you can ask why?
Another tool that might be useful for you is the Simulink Debugger.