Open the m file for System Objects in MATLAB - matlab

I am trying to use the Communications Toolbox in Matlab. In this toolbox there are a number of built in Systems Objects for example
1) comm.PSKModulator
I want to examine the .m file and see how these system objects are implemented. So I wrote down the command
open comm.PSMModulator
However, that doesnt help. Does anyone know why it doesn't work or maybe one cant access such code?
Update
When I write down which comm.PSKModulator I receive the following
/Applications/MATLAB_R2014a.app/toolbox/comm/comm/+comm/PSKModulator.p % comm.PSKModulator constructor
and where I write open comm.PSKModulator I get
Error using open (line 146)
File associated with
'/Applications/MATLAB_R2014a.app/toolbox/comm/comm/+comm/PSKModulator.p' not found.
Thanks

Some System objects may be implemented in C++ and does not have much to show in MATLAB code which might be the reason this is p-coded. You need to check the corresponding Simulink block documentation for description of the algorithm used. You can find documentation for M-PSK Modulator Baseband at http://www.mathworks.com/help/comm/ref/mpskmodulatorbaseband.html which has more description about the algorithm implemented.

Related

How do I find selfor in Octave?

I need to implement unsupervised neural network using Octave. For that, I need to use "selforgmap" function. How do I find that function in octave or what are the packages include this function?
When I use "selforgmap", I got an error like this.
selforgmap
error: 'selforgmap' undefined near line 1 column 1
help selforgmap
error: help: 'selforgmap' not found
As of now there does not appear to be any implementation of selforgmap in octave or any of it's packages. The current neural net package, nnet, can be found at Octave Forge and the Function Reference link will show you everything currently included.
The link Andy commented with above to a current reworking if the nnet package also does not currently include selforgmap, but this could obviously change. The included function files can be seen inside the inst folder.
if MATLAB's selforgmap is not an option for you, you will either need to code your own implementation or switch bto another programming language. A quick search does reveal a Python implementation of selforgmap that may serve your purpose.

Run Simulink from Matlab function

I am running Simulink using FastRestart, as I need to start and stop the simulation multiple times changing parameters. When I run Simulink from the main script, there are no problems. However, as soon as I make the script a function so that I can run it for different input data, I get an error that is clearly related to Simulink not seeing the Matlab workspace within the function.
To be more precise, say sfile is my Simulink file, then I run the following lines AFTER having initialized all variables I need in structures in Matlab:
load_system(sfile);
set_param(sfile,'FastRestart','on');
set_param(sfile,'SaveFinalState','on');
set_param(sfile,'SaveCompleteFinalSimState','on');
set_param(sfile,'SimulationCommand','update');
At the last line, I get the error that Simulink does not recognize mdl.tStep (which is the time step), as mdl is not a recognized structure. In fact, it is and if I run Simulink from the main script everything is fine.
Now, in the past, I would have used
options = simset('SrcWorkspace','current');
However, an expert I know has advised me against simset (as it may get deprecated in the future) and encouraged me to use set_param instead. I have
looked up the options for set_param on-line, but I could not find the setting for the Matlab workspace.
Any help would be greatly appreciated. Thank you in advance!
In many instances it is better to use the Model Workspace rather than the Base Workspace:
hws = get_param(model, 'modelworkspace');
hws.assignin('mdl',mdl);
At least be aware that this option exists.
A solution to your problem might be to use the assignin-function to all the variable whose value you want to pass to simulink in your matlab base workspace. To do so just use
assignin('base','mdl',mdl)
Having the variable in your base workspace should allow simulink to see it.

Cannot use some Matlab MPC Toolbox functions

I'm trying to use for example setoutdist Matlab function from the MPC Toolbox (I'm using Matlab R2013a on Windows 8.1). As a response I'm receiving:
Undefined function 'setoutdist' for input arguments of type 'ss'.
I am able to get help about this function using help setoutdist. When I'm typing the function name and left parenthesis I'm receiving prompt with list of the arguments. When I'm using which setoutdist -all I'm receiving proper output:
C:\Program Files\MATLAB\R2013a\toolbox\mpc\mpc\#mpc\setoutdist.m % mpc method code here
But the function doesn't work even in default Matlab path, so I don't think it is shadowed.
The same is with the other functions, for example setindist, setestim, mpc_struct, etc. but mpc, mpcstate and mpcmove functions works correctly.
I was trying: clear all, clear classess, rehash toolbox, rehash pathreset, rehash toolboxreset, restoring default paths using pathtool. I've blocked the antivirus and added exeptions to it's list. I've even reinstalled my Matlab, nothing helped.
Maybe this is significant: when I'm trying to edit the setoutdist.m I'm receiving message that access is denied.
I will extremly appreciate any help...
How are you calling setoutdist? The correct syntax is one of the three (see documentation - for R2014b):
setoutdist(MPCobj,'integrators')
setoutdist(MPCobj,'remove',channels)
setoutdist(MPCobj,'model',model)
where MPCobj is a Model Predictive Controller object, created for example with the mpc function. It looks like from the error message that you are calling the function with a state-space object, which is not allowed (I'm guessing).

running compiled matlab from matlab

I am trying to run compiled MATLAB code (by mcc) from inside MATLAB in a way that I can avoid using another license that is required by the compiled code. We need this because we run this same specific code part again and again and execution is stuck due to license waiting. We don't want to buy tons of this specific license just to mass run the same part. Is there any way to do this? tutorial?
Is it possible to compile a .m file to dll/so and wrap it like a mex and call it from MATLAB on the fly? How would I pass and retrieve complex arguments?
According to
http://www.mathworks.de/products/compiler/description3.html
creating shared libraries should well be possible.
Concerning passing and retrieving complex arguments:
If you plan to use mex, I'd assume you should be able to call the shared-library "main"-function with any arguments you'd like, using the mxArray type that you'll have to use anyway.
To run the MATLAB-compiled code in MATLAB, you want codegen, part of the MATLAB Coder. See this blog post on generating C code from MATLAB. The alternative, deploying code with mcc/mbuild and then reloading it into MATLAB with loadlibrary is rather contorted, and I wouldn't advice it.

Why can't Matlab R2010 load neural network objects from R2007?

I have a Neural Network that I've save to a .mat file in Matlab 2007.
I'm trying to load the neural network from the file with load filename.mat.
This worked great with versions R2007b and R2008, but when I try to load in R2010b I get the following message:
Warning: An error occurred when running a class's
loadobj method. The object that was loaded from the
MAT-file was a copy of the object before the loadobj
method was run. The rest of the variables were also
loaded from the MAT-file.
The encountered error was:
Reference to non-existent field 'name'
The weird thing is that it appears as if the variable holding the Neural Network exists, but it's not working properly. None of the functions that use the neural network work in R2010.
Has anyone encountered a similar problem ? How can I save the Neural Network so it will be compatible with Matlab R2010?
Or even better, how can I just load it properly in Matlab 2010?
Yes, it seems other people have encountered this problem (neural networks not loading in MATLAB 2010), according to this MATLAB Central post, in which Andreas Goser (Technical Support Manager at Mathworks) suggests:
If you see this issue in the future, please contact Technical Support and refer to solution 1-EGNM3S.
Apparently you need "a fixed net.m file" which technical support can provide. I haven't tested it, since I don't have that problem myself.
Carefully reading the error message, I would say that the variable you see loaded contains the "raw" object that was stored in the .MAT file, quite possibly a struct. You can run whos myvarname to check. To "revive" this struct into an object it needs to be processed by the overloaded loadobj function for its object type, which is usually automatically called by MATLAB's load function. In this case the loadobj that comes with the neuronal network object in R2010 seems to not be fully backwards compatible...
I suspect that the underlying objects for the neural net have changed since 2007b and that the definition in R2010b is not compatible with the data stored in the MAT-file.
I recommend following Jonas's answer. Alternatively, you might try loading it and re-saving it in an intermediate MATLAB release, or saving the data from the neural net objects and rebuilding it in R2010b.