Alex Rivera | Logout

How to slice a struct array?

Asked 2011-12-25T19:21:38.047
8

How can I extract a specific field from each element of a Matlab struct array?

>> clear x
>> x(1).a = 6;
>> x(2).a = 7;

I'd like an array containing 6 and 7. Neither x(:).a nor x.a do what I want.

>> x(:).a

ans =    

     6


ans =

     7
Edit
Report

1 Answer

-1

Sadly, I am almost sure that MATLAB has no nice way of doing what you want. You will have to either use a for loop to construct a new array, or else go back and redesign your data structures. For example you might be able to use a struct-of-arrays rather than an array-of-structs.

answered 2011-12-25T19:26:13.177

Your Answer