how to use string to define function and use to store parameters whose values are constants but requires in different sub function?
Show older comments
how to use string to define function and use to store parameters whose values are constants but requires in different sub function?
i have attached image in which parameters x1,x2,....,xn.
if i want to save it in one function and called it when required in function. but using string if x1 is match it gives it values.
[SL: formatted question as text not code]
4 Comments
Ameer Hamza
on 19 Mar 2020
The question is not clear. Give a clear example of what you want to do by giving some input data and specifying what your intended output is.
chirag patel
on 20 Mar 2020
Stephen23
on 20 Mar 2020
Why do you need a dictionary? Basic indexing would probably do what you need.
chirag patel
on 20 Mar 2020
Answers (1)
Sourabh Kondapaka
on 27 Mar 2020
Hi,
Can you be a bit more descriptive in what you are trying to achieve.
To define a function as a string you can use "str2func()" function and pass the arguments.
As Stephen Cobeldick suggested, it would be better to use a cell array to store values instead of several different variable names.
If this function takes variable number of arguments you can use "varargin" as shown in the code below.
% getDetails is a sample function name. You need to define what the function does elsewhere.
funcHandle = 'getDetails';
funcHandle = str2func(funcHandle);
[output1, output2] = funcHandle(funcHandle, varargin);
Refer the following link for more information on “str2func()”:
Refer the following link for more information on “varargin”:
Categories
Find more on Simulink Check in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!