Simulink customized block - matlab

I want to create a customized block in Simulink where only input and output ports are defined and then add any other block like machine learning (if possible) to process the input and generate the output. I have searched a lot but the examples on MathWorks are very specific. I am looking after a very general solution where a simple and empty block with only input/output ports can be added and output is generated based on the input.
Thanks in advance,
D.

Related

Is it possible to send commands between two MATLAB windows open on the same computer?

I want to have two MATLAB windows open on the same computer. The desired scenario is as follows: MATLAB window 1 is continuously running a script that has nothing to do with MATLAB window 2. At the same time, MATLAB window 2 is running a script that continuously checks for a certain condition, and if it is met, then it will terminate the script running on MATLAB window 1, and then terminate its own script as well. I want to have two MATLAB windows instead of one since I believe it will be more time efficient for what I am trying to do. I found an interesting "KeyInject" program at http://au.mathworks.com/matlabcentral/fileexchange/40001-keyinject , but I was wondering if there is a simpler way already built into MATLAB.
Do you want simple, or a flexible, infinitely expandable version 1.0? Simple would be to trigger System A via a file created by System B.
Simple would have System B create a file, then System A would check for the file with the command
if exist ( fileName, 'file' )
then do your shutdown commands. On startup, System A would delete the file with
delete ( fileName );
The second option is to use the udp command. UDP allows any data to be sent between processes, whether on the same computer or over a network. (See https://www.mathworks.com/help/instrument/udp.html for more info).
I see several ways:
Restructure to avoid this XY problem
Use (mat) files (as Hoki suggested), possibly using the parallel computing toolbox to keep everything in one MATLAB session.
Write some MEX functions that communicate with each other via a global pipe.
Write an Auto(Hot)key script.
Option 2 is probably easiest. Take a look at events and listeners if you write in OOP, otherwise, you'd have to poll inside a loop
Option 3 is harder and way more time consuming to implement, but allows for much faster detection of the condition, and much faster data transfer between the sessions. Use only if speed is essential...but I guess that doesn't apply :)
Option 4: the AutoHotkey solution is probably the most Horrible Thing® you could do on an already Horrible Construction®, but oh what fun!! In both MATLAB sessions, you create a (hidden) figure with the name Window1 or Window2, respectively. These window names are something that AutoHotkey can easily track. If the conditions are met, you update the corresponding window name, triggering the remainder of the AutoHotkey script: press a button in the other window! If you need to transfer data between the windows: you can create basic edit boxes in both GUIs, and copy-paste the data between them. If you're on Linux: you can use Autokey for the same purpose, but by then you're basically writing Python code doing the heavy lifting, so just use Python.
Or, you know, use KeyInject. Less fun.

Using .do files with ModelSim (10.3a)

Here is the (brief) context for my question :
I am working in VHDL (with Microsemi's Design Suite, Libero) and I use ModelSim to simulate my work. To that extent, I use a classic VDHL TestBench and, to save time, a .do Macro File.
This .do Macro file contains very basic commands such as "restart" or deleting/adding waves.
Even if I'm not expecting much from such a file, it would be convenient for me to include in it more actions, that I have to perform by hand with the Graphical Interface like, something that I use quite a lot : combining signals into a custom bus. This action is very simple to do in Modelsim's graphical interface but I can't find anywhere how to perform this in a .do Macro File.
So my question is :
Where can I find some good documentation regarding these ModelSim's .do Macro Files?
Or am I missing the point about the use of these files? Is it relevant to use it in sich a way?
I really hate to ask this kind of question here but, even if I was able to find some info here and there on various websites, I found nothing significant. I have been through quit a lot of ModelSim help documents or user guides but it almost always focused on the graphical interface.
You can find a command reference manual for your ModelSim version here:
www.microsemi.com/document-portal/doc_view/134097-modelsim-command-reference-manual-v10-3a.
You should also be able to find this and other documentation in ModelSim under "Help" > "PE Documentation - PDF Bookcase" (substitute 'PE' for the edition you are running).
You should see all the usual commands like 'add wave'. These can be used in .do files, and TCL script files.
You can use dividers to seperate signals with
add wave -divider -heigth 10 $DIVIDER_NAME
and also if you want to expand-collapse signals, you can add signal with
add wave -group $GROUP_NAME -position end ....
http://users.utcluj.ro/~baruch/resources/ModelSim/modelsim_user.pdf page 306

Simulink - Code to 'Comment through' blocks

I've built a Simulink model and I would like to 'Comment Through' some blocks via a MATLAB script. I am using MATLAB 2013b.
I know that the command set_param('BlockAddress','Commented','on') comments out the block from the simulation, but that's not the same thing.
Instead of the string 'Commented' in the set_param code, I was hoping to find a block property that defines the 'Comment Through' state, but I could not find it in MATLAB's Common Block Properties page.
Does anyone know if such property is defined, or, if not, a different work-around to comment through blocks by using a script?
Despite MATLAB did not mention 'through' among the possible values for the 'Commented' property, this is the code to comment out blocks using set_param:
set_param('BlockAddress','Commented','through')

How can I call Matlab functions using Erlang?

I would like to call some Matlab functions using Erlang.
I have two separate network models (one comms/control, one energy)
Ideally I would like an Erlang process to send a message which causes some Matlab code to run. After the Matlab code has finished it must notify Erlang.
What is the simplest way of doing this?
I am running Windows 7. Matlab appears to require use of Microsoft Component Object Models which do not seem to be commonly used with Erlang - hence my question...
Thanks,
You can run Matlab statements from the command line:
matlab -r "statements"
Erlang gives you the opportunity to open ports to execute OS commands. Combining the two features should do the job for you. Have a look to the os:cmd/1 function. For example, you could simply do:
os:cmd("matlab -r STATEMENT").

Syntax to save Neural Network Object in Matlab R2011a

I have trained a neural network using MATLAB and I need to save it to be able to test it in the future.
I would like the appropriate syntax on how I can do this. Please note that I am aware of the graphical toolbox which easily lets you save a trained network, but unfortunately the options provided are not sufficient for me and so I have to create and train a network of my own using code.
I have tried the following syntax to save a trained network. (Most of the syntax is copy paste from the internet with little experimentation of my own.)
save('net.mat', net)
save(net)
save('net.net', net, '-mat')
save('net.net', net)
But I always seem to get the same error:
??? Error using ==> save
Argument must contain a string.
If there are experienced users who could lead me to a concrete answer which is sure to work, I would be very grateful.
From here.
When using parentheses (function syntax) you need to use quotes around the object name. Note that the function requires an object description and not the object itself. This makes sense since it can also take wildcards that describe multiple objects and then save them all into the '.mat' file.
In short, when you're using parentheses, use this:
save('net.mat', 'net')
Alternatively you can use the command syntax (no parentheses) and then quotes are optional. All options below are valid (and equivalent):
save net.mat net
save net.mat 'net'
save 'net.mat' net
save 'net.mat' 'net'
See also Command vs. Function Syntax