Friday, 15 June 2012

matlab - how do I sort a struct by values? -



matlab - how do I sort a struct by values? -

i have struct:

s = p_10_50_10_70: 0.1176 p_10_50_15_10: 0.9235 p_10_50_15_70: 0.2456 p_10_50_base: 0.0100 p_10_70_15_10: 0.0895 p_10_70_15_70: 0.0053 p_10_70_base: 6.3711e-06 p_15_10_15_70: 0.1892 p_15_10_base: 0.0047 p_15_70_base: 0.3377 p_5_30_10_50: 0.0864 p_5_30_10_70: 0.0014 p_5_30_15_10: 0.0654 p_5_30_15_70: 0.6165 p_5_30_5_70: 0.0052 p_5_30_8_30: 0.8106 p_5_30_8_70: 0.0378 p_5_30_base: 0.6113 p_5_70_10_50: 0.2215 p_5_70_10_70: 0.7448 p_5_70_15_10: 0.2444 p_5_70_15_70: 0.0221 p_5_70_8_30: 0.0024 p_5_70_8_70: 0.5382 p_5_70_base: 2.1956e-04 p_8_30_10_50: 0.0699 p_8_30_10_70: 8.1918e-04 p_8_30_15_10: 0.0599 p_8_30_15_70: 0.7169 p_8_30_8_70: 0.0218 p_8_30_base: 0.9146 p_8_70_10_50: 0.5467 p_8_70_10_70: 0.3395 p_8_70_15_10: 0.5552 p_8_70_15_70: 0.0775 p_8_70_base: 0.0015

`

i want sort values, , realise may not best datatype kind of sorting. using matlab r2012b not have table datatype, how can end info construction contains both key names , values, ordered numeric value?

going forwards best datatype key value pair array such this, if want sort value?

thanks!

looks it:

[~, idxs] = sort(cell2mat(struct2cell(s))); s = orderfields(s, idxs);

edit: final question, yeah i'm not sure there great options. thing improve you've got might class, cell array of strings , vector of corresponding values, , setter/getter functions create access efficient.

matlab struct

No comments:

Post a Comment