MATLAB: How to create a 1x(many) structure from individual variables

structures struct

I'm trying to replicate a pairs trading method (GGR method) but I fail at the very beginning. I import a large file of daily stock returns and a few other variables. Now what I want to achieve from here is visualized in the picture. I want to create a structure (struct) which contains all the variables and which is sorted on one of the variables (PERMNO). All I'm able to achieve is a 1×1 structure with nine fields but it should be a 1xmany (3507 in the picture) structure.
To be clear, the picture is not my own result but it is what I want to achieve. Can someone tell me how to create a 1xmany structure which is sorted on the PERMNO variable? Thanks in advance

Best Answer

[~, sortidx] = sort( [ALL_NYSE_Equity.PERMNO] );
sorted_equity = ALL_NYSE_Equity(sortidx);