How to access and store selected fields from a dynamic structure in matlab?
<p>I have a huge dynamic structure. It looks something like this:</p>

<pre><code>s.one.name = 'Mr. Doe';
s.one.time = '12:00';
s.one.ID = '209';
s.one.data = 'Data1';

s.two.name = 'Ms. Jane';
s.two.time = '13:00';
s.two.ID = '210';
s.two.data = 'Data2';

s.three.name = 'Ms. Alice';
s.three.time = '14:00';
s.three.ID = '212';
s.three.data = 'Data3';

s.four.name = 'Mr. Smith';
s.four.time = '14:00';
s.four.ID = '212';
s.four.data = 'Data4';
</code></pre>

<p>Now, I want to access and store only the first two fields <code>one</code> and <code>two</code> (out of all the given fields) and its corresponding data into a new dynamic structure <code>snew</code>.</p>

<p>I have tried doing the following things:</p>

<pre><code>for ii = 1:2
    snew = [s.(ii)];
end
</code></pre>

<p>Error: <code>Argument to dynamic structure reference must evaluate to a valid field name.</code></p>

<p>Could anyone help me out in acheiving this task?</p>

<p>Thank you in advance</p>