I have created a Mex-file (.mexw64) from my matlab project using Matlab Coder. The problem is that the output is not the same when I run the mex-file as when I run the project in a normal way. Often the variation in the numbers are really small:
5.4463.. -> 5.4465.. etc.
I'm thinking that there might be a problem related fixed point computations. What should I look for?
Expected differences from MATLAB are explained in the documentation. See the section on Floating-point Numerical results:
MATLAB Coder Documentation on expected differences.
Related
There is a file called normxcorr2_general on MathWorks here that the author claims always gives correct answers while Matlab's built-in normxcorr2 gives incorrect answers when the two input matrices are close in size. After doing some testing, it is clear that the two functions do give significantly different outputs when the inputs are the same size.
Is normxcorr2_general actually more accurate? I don't have much experience in Matlab and I'm having trouble figuring that out from reading through the function script.
Edit: To clarify, if I understand it correctly then these functions are both implementing equation number (2) in this paper about computing normalized cross-correlations.
I am working on an artificial neural network. I want to implement it in Matlab, but I am unable to find a proper activation function. I need a step function because my output is either 0 or 1. is there any function in Matlab that can be used for this kind of output. Also, I want the reverse function of the same activation function. logsig and tansig are not working for me.
Both tansig and logsig are part of the Neural Network Toolbox as the online documentation makes clear. So, if which tansig returns nothing, then you don't have that toolbox (or at least don't have a version current enough to contain that function). However, both of these functions are extremely simple, and the documentation even gives you the formulae under the "Algorithms" section: tansig, logsig. Both can be implemented as a one line anonymous function if you wanted.
If your question is actually about how to produce a Heaviside step function, Matlab has heaviside (it's part of the Symbolic Math toolbox but a pure numeric version is included – type edit heaviside to see the simple code). However, note that using such a non-differentiable function is problematic for some types of neural networks as this StackOverflow question and answer addresses.
Heaviside did not work for me.. i finally normalized my data between 1 and -1 and then applied tansig.
Thanks
I am trying to get the MATLAB toolbox SOSTOOLS to work inside a MATLAB R2010b (7.11.0.584) but get the following error:
??? Error using ==> maple at 54 The MAPLE command is not available.
Googling it I found out that MATLAB stopped using Maple at some stage and switched to MuPad.
Short of switching to an older version of MATLAB, is there a known workaround for this situation?
A solution in the form of installing Maple as the symbolic toolbox engine is not possible with your version of Matlab.
This outlines an alternative possible solution, I did not find a concrete workaround that will spare you work. I recommend you contact the authors, or check for octave versions with the same functionality.
The change to MuPad is a problem that's been posted numerous times, and there is a useful discussion of differences between Maple and MuPad here:
http://www.walkingrandomly.com/?p=178
For some commands it looks like a simple translator might work. Most of the implementation would apparently be in parsing the output from MuPad and turning it into what Maple would generate. The input to MuPad and Maple is apparently equal most of the time, but read the doc above.
To write a translator, you redirect calls to maple by placing in your path the following function maple that calls mupad:
function output=maple(input);
%prepare input here (if necessary) ...
output=mupad(input);
% parse the output (if necessary) ...
More likely than not, a naive call to this re-director will not solve the problem without some input/output parsing.
Is it possible to use a MATLAB code on Scilab? Is that what is meant when saying that Scilab is a "clone" from MATLAB?
There is a tool to automatically convert Matlab source to Scilab source, it's called M2SCI. A script parses the Matlab source code and replaces Matlab-specific functions by Scilab ones. See the documentation of the mfile2sci function.
Yes you can use MATLAB code on scilab. See these links for more information:
http://help.scilab.org/docs/5.4.0/fr_FR/section_36184e52ee88ad558380be4e92d3de21.html
http://help.scilab.org/docs/5.4.0/en_US/index.html
I would not bet on it. But if your code is simple enough chances are good.
Problems are:
There is encrypted p-code in Matlab that Scilab will not be able to open.
Matlab usually comes with a number of toolboxes that might not be available to you (i think especially Simulink)
last but not least (i don't know about scilab) there usually are minute differences in how functions are implemented.
There are a number of projects out there trying to replicate/replace MATLAB:
Julia language: which has a relatively similar syntax to MATLAB and offers great performance, but still lacks a lot of toolboxes/libraries, as well as not having a GUI like MATLAB. I think this has the brightest future among all MATLAB alternatives.
Python language and its libraries NumPy and matplotlib: which is the most used alternative. I think at this moment the community is a couple of orders of magnitude even bigger than MATLAB. Python is the de facto standard in machine learning and data science at the moment. But still, the syntax and memory concept is a bit far from what people are used to in the MATLAB ecosystem. There are also no equivalent to SIMULINK, although Spyder and Jupyter projects have come a long way in terms of the development environment.
Octave: is basically a clone of MATLAB to a point they consider any incompatibility as a bug. If you have a long MATLAB code that you don't want to touch, this is the safest bet. But again no alternative for SIMULINK.
SciLab and it's fork ScicoLab are the best alternatives in terms of GUI, having a SIMULINK replica xcos / scicos and a graphical user interface development features. However the community is not as big as Octave and the syntax is not completely compatible. Sadly the Scilab development team has gone through a devastating family crisis leading to the software falling behind.
Honorary mention of Modelica language implementations OpenModelica and jModelica for being a superior alternative to SIMULINK-SimScape. You should know that you can load Modelica scrips also in xcos and scicos. If you want to kno wmore about JModelica you may see this post.
you may check the MATLAB's Alternativeto page to see more Free and Open source alternatives.
I would like to know if there is any available Gaussian hypergeometric function (2F1 function) code for Matlab.
I perfectly know that in the newest Matlab releases there is the hypergeom function, but it works really slow.
Therefore I was wondering about the existance of any mex function or whatever similar code performing what hypergeom does.
I thank you all in advance for support.
Best regards,
Francesco
The GNU Scientific Library implements hypergeometric functions including 2F1. You shouldn't have too much trouble wrapping that inside a mex-file.
I expect you'll find other sources knocking around on the Internet too.
Do report back and let us know if it does work faster than the intrinsic function.
After googleing a bit in the Internet, I came up with this tool provided within the Mathworks File Exchange:
http://www.mathworks.com/matlabcentral/fileexchange/35008-generation-of-random-variates/content/pfq.m
It consists of 1900 distributions, and among them the Gaussian hypergeometric function 2F1.
Furthermore, it has better performances than the standard hypergeom function.