0

I want to take a cell array from the user containing the number of zeros and poles of each transfer function in a system identification app that I am designing in MATLAB's app designer.

User enters something like this:

{[2,1], [1,0]; [1,0], [2,1]}

EditField or TextArea treats this input as a char array or string, But I want to re-convert it to a cell array of numbers, not strings. How is that possible?

MHTB
  • 39
  • 5

1 Answers1

0

You can use eval to evaluate the string to get the resulting numbers. This works if it has numbers, variables and functions accessible from the workspace where you are running eval. See documentation for eval at https://www.mathworks.com/help/matlab/ref/eval.html. If there is a variable in the expression for example as, {[2,1], [1,0]; [1,0], a} with a defined in the base workspace then you need to use evalin. evalin lets you specify the workspace where the expression needs to be evaluated.

Finally if it is not a cell array and contains only an array of numbers then str2num also can do the job of converting the string to numbers.

Navan
  • 4,407
  • 1
  • 24
  • 26