read function intputs into cell array

1 visualización (últimos 30 días)
Yunyu Hu
Yunyu Hu el 27 de Feb. de 2020
Comentada: Yunyu Hu el 24 de Mzo. de 2020
Hello,
I have script calls functions like this:
func1('A1',[1],'min',0,'max',1)
func1('A2',[1],'min',0,'max',100)
...
func2('B1',[1],'min',0,'max',1)
func2('B2',[1],'min',0,'max',1)
...
I want to gather all these inputs into a list. How can I get the functions inputs as a cell array? I do not want to use regular expression, because the real situation is much more complex.
Thanks

Respuestas (1)

Shiva Kalyan Diwakaruni
Shiva Kalyan Diwakaruni el 24 de Mzo. de 2020
Hi,
This is to my understanding that you want to get function inputs as a cell array instead of mentioning each arguments specifically inside function definition as below.
func1('A1',[1],'min',0,'max',1)
func1('A2',[1],'min',0,'max',100)
...
func2('B1',[1],'min',0,'max',1)
func2('B2',[1],'min',0,'max',1)
...
Following can be used arguments as varargin that accepts a variable number of inputs as shown.[PP1]
Func1(varargin)
Func1(varargin)
….
Func2(varargin)
Func2(varargin)
…..
Following can be used to declare a global cell array and add them into a global cell array by running a for loop through varargin inside every function.
Func1(varargin)
Global cell_array
For k = 1:numel(varagin)
Cell_array = [cell_array,varargin[k]]
For more information on varargin please visit the below link:
  1 comentario
Yunyu Hu
Yunyu Hu el 24 de Mzo. de 2020
Thanks for the answer but sorry your understanding is not correct. The part:
func1('A1',[1],'min',0,'max',1)
func1('A2',[1],'min',0,'max',100)
...
func2('B1',[1],'min',0,'max',1)
func2('B2',[1],'min',0,'max',1)
...
are written in a script. I do not want to call the functions, but just read the text of this script and make a cell:
cell1={'A1',[1],'min',0,'max','1';
'A2',[1],'min',0,'max','100';
...}
cell2={'B1',[1],'min',0,'max','1';
'B2',[1],'min',0,'max',1;
...}
I do not want to use regular expression, because there are also comment and other stuff in the script. And user can also write : func2('B2', [1], 'min',0,'max',1) or some other situation.

Iniciar sesión para comentar.

Categorías

Más información sobre String Parsing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by