MATLAB: Passing a string to a function

struct

I have created several structures based on my data using eval. The names of the structures and the names of the fields are stored in seperate arrays and the names can be different depending on the data. How can I pass these strings into a functin such as fieldnames? I keep gettting errors that the input arguments cannot be 'cell' or 'char'. So if the name of my struct is in name(1,1) how can i run fieldnames(name(1,1))

Best Answer

namestruct = 'test';
test = struct('x',randn(100,1),'y',randn(100,1));
namez = fieldnames(eval(namestruct))