MATLAB Answers

Merging Arrays in a Struct and Sorting them

1 view (last 30 days)
hamzah khan
hamzah khan on 26 Dec 2019
Edited: Stephen Cobeldick on 26 Dec 2019
Hello, I have a struct like this:
talha4.JPG
I want to join its two arrays into one array and then sort them in ascending order, I am trying this code, but it is not giving me results:
c = [v(1) v(2)]
sort_c = sort(c);

  0 Comments

Sign in to comment.

Accepted Answer

Bhaskar R
Bhaskar R on 26 Dec 2019
result = sort(struct2array(v), 'ascend')

  1 Comment

Sign in to comment.

More Answers (1)

Stephen Cobeldick
Stephen Cobeldick on 26 Dec 2019
Edited: Stephen Cobeldick on 26 Dec 2019
A more robust solution, where v is your 2x1 structure:
out = sort([v.IndividualStiffnessMatrix])
Note that your field name is misspelled "Indivual..."

  0 Comments

Sign in to comment.

Sign in to answer this question.