<p>I want to combine two structures with differing fields names.</p>

<p>For example, starting with:</p>

<pre><code>A.field1 = 1;
A.field2 = 'a';

B.field3 = 2;
B.field4 = 'b';
</code></pre>

<p>I would like to have:</p>

<pre><code>C.field1 = 1;
C.field2 = 'a';
C.field3 = 2;
C.field4 = 'b';
</code></pre>

<p>Is there a more efficient way than using "fieldnames" and a for loop?</p>

<p><strong>EDIT:</strong> Let's assume that in the case of field name conflicts we give preference to <code>A</code>.</p>

In C, a struct can have another struct as one of it's members.  While this isn't exactly the same as what you're asking, you could end up either with a situation where one struct contains another, or one struct contains two structs, both of which hold parts of the info that you wanted.
psuedocode: i don't remember the actual syntax.
```
```
A.field1 = 1;
A.field2 = 'a';
A.field3 = struct B;
```
```
to access:
    A.field3.field4;
or something of the sort.
Or you could have struct C hold both an A and a B:
```
```
C.A = struct A;
C.B = struct B;
```
```
with access then something like
```
```
C.A.field1;
C.A.field2;
C.B.field3;
C.B.field4;
```
```
hope this helps!
EDIT: both of these solutions avoid naming collisions.
Also, I didn't see your
```
matlab
```
tag.  By convention, you should want to edit the question to include that piece of info.