필터 지우기
필터 지우기

How to robustly parse string into output arguments, function handle and input arguments

조회 수: 4 (최근 30일)
In a textbox in a GUI, a user can enter a function that they wish to execute. For example,
[ out1, out2 ] = name_of_a_function(in1, in2, in3);
When submitted, this is communicated to the backend as the string
"[ out1, out2 ] = name_of_a_function(in1, in2, in3);"
Is there a robust way to decompose this string into the names of output arguments, function handle and input arguments taking into account that users can use any valid Matlab syntax and any number of output and input arguments, perhaps providing input arguments directly as vectors, matrices or cell arrays instead of using variable names?

채택된 답변

Chunru
Chunru 2021년 6월 11일
It will be a challenging task. Hope the following can help
t =mtree('[ out1, out2 ] = name_of_a_function(in1, in2, in3);')
t = mtree (complete: 13 nodes)
dumptree(t)
1 *<root>: EXPR: 1/16 2 *Arg: EQUALS: 1/16 3 *Left: LB: 1/01 4 *Arg: ID: 1/03 (out1) 5 >Next: ID: 1/09 (out2) 6 *Right: CALL: 1/36 7 *Left: ID: 1/18 (name_of_a_function) 8 *Right: CALL: 1/37 9 *Left: ID: 1/37 (in1) 10 >Next: CALL: 1/42 11 *Left: ID: 1/42 (in2) 12 >Next: CALL: 1/47 13 *Left: ID: 1/47 (in3)

추가 답변 (0개)

카테고리

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

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by