MATLAB: Is it possible to extract all fields from a structure automatically

a really bad ideastructvariable

I have data in the form: mydata.x = 100; mydata.s = 'abc'; mydata.Y = [1 2 3]; And I want variables x = 100; s = 'abc'; Y = [1 2 3]; How to extract variables automatically? (suppose that I don't know the names of the variables!)

Best Answer

You seem intent on magically making variables pop into existence in the workspace, so here is probably the least-worst way of doing that. The trick is to change the save command by adding the '-struct' option:
>> S.name = 'anna';
>> S.data = 1:3;
>> save('temp.mat','-struct','S')
and then load it like this:
>> clear
>> load('temp.mat')
>> name
name = anna
>> data
data =
1 2 3
and you will find all of those variables in your workspace.