Extract field of struct array to new array

I have a structure that has 2 fields: time and pose . I have several instances of this structure consisting of an array, so an example of this:

 poses(1) -time = 1 -pose = (doesn't Matter) poses(2) -time = 2 -pose = (doesn't Matter) poses(3) -time = 3 -pose = (doesn't Matter) ... 

Now when I type this:

  poses.time 

I get this:

 ans = 1 ans = 2 ans = 3 

How can I take this conclusion and put it in a vector?

+7
source share
2 answers

Use brackets:

 timevec=[poses.time]; 

complex matlab, I know that I know, you just need to remember this if you are working with structs;)

+13
source

In cases where the field values ​​are vectors (of the same size), and you need the result in the form of a matrix:

 posmat = cell2mat({poses.pose}'); 

Returns each pose vector in a different posmat line.

+1
source

All Articles