How to cut an array of structures?

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

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

I need an array containing 6 and 7. Neither x(:).a nor xa do what I want.

 >> x(:).a ans = 6 ans = 7 
+6
source share
3 answers

No problem - just use:

 arr = [xa]; 

He will fulfill all the values ​​you need. If you have more complex data, you can use curly bracers:

 b(1).x = 'John'; b(2).x = 'Doe'; arr = {bx}; 
+9
source

Unfortunately, I'm pretty sure MATLAB has no good way to do what you want. You will either have to use a for loop to build a new array, or go back and reverse engineer your data structures. For example, you can use an array structure rather than an array structure.

0
source

For a multidimensional array you need

 reshape([xa], size(x)) 
0
source

Source: https://habr.com/ru/post/904459/


All Articles