matlab function parser on gui - matlab

I need to do a parser on my gui in matlab in which you can type your own function formula that will be used for computations. I came up with to make function that gets function from edit box as a string and saves it to m-file as a function. But any further calling changed file do not bring expected results if the first form of function were stored in memory. Do you have any other ideas to solve it?

Instead of writing the code to an m-file, take a look at the eval function.

Related

Calling a function from stateflow

I am trying to call a function (can be matlab function or a simlink function) from a stateflow in one subsystem, the function must be located in another subsystem as shown below:
enter image description here
The first subsystem will have a stateflow which calls this function. It doesn't really matter if this function is a M-script, currently I do not know how to work around with matlab function (mscript) as it needs the arguments of the functions as inputs.
Is there any workaround for this problem?
ml.functionname() would solve the issue, if passing the argument in a function be sure u have them defined in model explorer for respective Stateflow.

How can I create multiple inputs for a matlab function block?

I want to restrict the variable that I use as input for a matlab function block, it must be only able to increase.
To achieve that i have tried to compare the variable and the previous sample of it in a matlab function, but i don't know how to create two inputs. To solve that i've tried to use a mux, but then i get an error. And google doesn't give me an explanation how to use a mux signal as input for a matlab function.
So that leaves me here with this low-level question.
Thanks in advance for your help and time. Cheers.
To use multiple variables in a function, you need to modify your function declaration at the first line of your function. The reference syntax is:
function [y1,...,yN] = myfun(x1,...,xM)
where x1 through xM are inputs. Your declaration with two inputs might look something like:
function [returnValue] = hasIncreased(previousSample, variable)
See the Matlab Function Documentation for more information.

Simulink, matlab functions

i can't find a way to use the same matlab function in more Simulink block. I used function block but in this way each time a have to copy all code changes. What is the best way to this?
Create a file named <function name>.m that contains your function, then have the function blocks have one line that simply invokes that function.

Matlab Simulink function

I am building a reduced order observer in MATLAB. The matrices are calculated using functions/script files outside matlab and simulink function blocks are using these functions to calculate values.
The problem is that some commands like 'acker', 'place' etc which used to work on command window/function/script files are not working in simulink function block and showing errors.
I tried using simin block to take these matrices from workspace but it is also showing errors which I can't understand.
Thanks for your help.
If I get your question correctly then, from User defined functions, you could add a Matlab function block with the following code:
function fcn(in)
%#codegen
coder.extrinsic('acker', 'place')
# Now you can use acker, place so add more code.

How to find call an external function from a GUI in MATLAB?

I have an external function (myfun.m) which will generate 4 images. I want to use a textbox in a GUI to give the function the input parameters (e.g. the name of the original picture), but I have no clue how I can run myfun.m in my GUI. PLease help
First, I would recommend having a different textbox for each input to your function. For example if your function asks for 4 inputs, I would have four textboxes. This will avoid pain on the user's end to format their text input a certain way, as well as pain on your end on parsing a long text string into several inputs.
Second, if your function is within MATLAB's path, then you can call that directly from your GUI no problem just as you would any of MATLAB's built-in functions. You probably want to make a push-button that has a callback to execute that functions.
The way the callback for this function should look is to l