필터 지우기
필터 지우기

how to use string to define function and use to store parameters whose values are constants but requires in different sub function?

조회 수: 29 (최근 30일)
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
Stephen23
Stephen23 2020년 3월 20일
Why do you need a dictionary? Basic indexing would probably do what you need.
chirag patel
chirag patel 2020년 3월 20일
For parameters 50 it is becoming tedious. So help how to use data dictionary.

댓글을 달려면 로그인하십시오.

답변 (1개)

Sourabh Kondapaka
Sourabh Kondapaka 2020년 3월 27일
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”:

카테고리

Help CenterFile Exchange에서 Dictionaries에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by