Converting Matlab anonymous functions to Scilab inline functions - matlab

Most of my Matlab functions can be converted with the mfile2sci function to Scilab functions except some functions that contain anonymous functions (for example f=#(x,y)sin(x)+log(y)). Is there a way to convert the anonymous functions to Scilab inline functions (for example, for the previous example deff('[z]=f(x,y)','z=sin(x)+log(y)')) so that I don't have to change my Matlab functions?

Yes, in its current state the Matlab to Scilab translator mfile2sci fails to translate anonymous functions, but this behavior can be improved by the following patch:
https://codereview.scilab.org/#/c/20916/
However, be warned that anonymous function occur most of the time when using "solvers" like fsolve, optim, ode solvers (e.g. ode45, ode15s,...), and that statements using these are never translated to working Scilab statements (a warning is given).

Related

Converting Matlab function (mscript) to simulink model

I wrote a M function (Mscript), but sadly I cannot use this function directly in my model (not even as Matlab function block), because of the TargetLink restrictions.
if there any way I can convert the function to a simulink model or do I have to do it from the scratch?
The latest version of targetlink does support the function block in simulink models.
An alternative to actual simulink blocks might be a stateflow chart. Targetlink is limited to the action language c, but still rewriting it in a stateflow function in c might be closer to the original m code than converting it to blocks.

Octave rasterread vs Matlab geotiffread

I have some Matlab code that uses the geotiffread function (mapping toolbox). Now I would like to port this code to Octave, and to do that I have to use the rasterread function (mapping octave forge package).
The two functions are not identical: the octave function should provide access to the same information of its Matlab counterpart, but the return values are quite different (structure arrays with different size/shape, fields, ...). Is there any resource, a part from the reference of the two functions, to map geotiffread and rasterread?

Are Syms and Symsum slow?

Im working on a huge matlab code in which I have a symbolic function G as well as its inverse invG and first derivative g defined using "syms" and I use "matlabFunction" in certain functions. These symbolic functions are called multiple times within various functions in the code. The problem is that my code is toooo slow and I suspect the symbolic functions are to blame.
Im also using "symsum" for some convergent series and sums.

What is actually symbolic variable in matlab?

I am new in learning matlab. when I am using the solve() function, matlab warning me that i must use a symbolic variable before using the solve function. but I actually don't know what the sym variable is. or What is the difference between the symbolic variables and the ordinary variables of the base workspace?
Symbolic variables are useful to express equations and manipulate them in an analytic manner. You can use them to manipulte them algebrically, without the need of actually associating any type of numbers.
Suppose you want the exact analytical form of a solution for an equation, in terms of symbols that express this function. Then you can use a sym variable to express and operate with the unkwons, rather than to use on numerical methods to find solutions
Symbolic variables are also useful to operate with tranfer funcions and perform simplications that are very tedious If done without a computer program.
You also can associate numbers with sym variables, once you have done all the all the intended operations.
If you don't want perform operations with algebraic variables, you should checkout the fsolve function

How can I call an m file in Simulink and put it to a block in my model?

How can I call an m file in Simulink and put it to a block in my model (without using an S function)? Does anybody have an idea? I'd really appreciate it.
If you're trying to apply a user-defined MATLAB function to Simulink signals, there are a few different ways to do this, depending on your objective. All options are available within the User-Defined Functions section of the Simulink library.
Use the MATLAB function block if you intend to generate code from your model. This block does have restrictions, the entire gamut of built-in MATLAB functions is not available.
Use the Interpreted MATLAB function block if you don't care about code generation, this block can make use of any functions.
Use the Fcn block if your m-file is trivial and contains a simple expression operating on the inputs. In this case you can type the expression directly into the block dialog and reference the input / output signals as shown in the documentation.
MATLAB Fcn block is the best solution to embed M-function file into Simulink model. However, be cautious which version of MATLAB you are using, e.g., with later versions of MATLAB Function Block can be implemented with M-function file with %#codegen and C compiler need to be with your MATLAB package. Good luck