MATLAB: How do you make multiple variable assignments from s struct

struct assignment

There has to be a straightfoward way to do this but I can't find it to save my life:
s = struct([]);
s(1).x = 1;
s(1).y = 2;
s(2).x = -1;
s(2).y = -2;
[x1, y1] = s(1); % where x1 is initialized to be s(1).x and y1 to be s(1).y
I have a struct with >10 elements. I'd really like to not have to assign variables one line at a time.

Best Answer

If you choose to do it the way Joseph Chang mentioned - then I would strongly advise that you change the eval statement to use dynamic fields instead, e.g.:
function a = extractfield(s,name)
a = s.(name)
end
You could remove the sub function entirely:
function varargout = extractfields(s)
name = fieldnames(s);
for ind = 1:length(name)
varargout{ind} = s.(name{ind});
end
end