csj
csj

Reputation: 23

Matlab: Convert string to cell

How to convert a string, containing a cell to a cell, fx:

astring='{1,[2,3,4],''bla''}'

To what i want:

a1x3cell={1,[2,3,4],'bla'}

The problem arises when using: Uicontrol: style "edit", which outputs the input value as a string, ie. converts input:

{1,[2,3,4],'bla'}

to output:

'{1,[2,3,4],''bla''}'

Upvotes: 2

Views: 1178

Answers (1)

Jonas
Jonas

Reputation: 74940

There are two possibilities:

Either use eval, as suggested by @Divakar

a = eval(string)

Or convert the string to an anonymous function and evaluate that

fun = str2func(['@()',string]);
a = fun()

Upvotes: 1

Related Questions