Sorting structure with vector field

4 次查看(过去 30 天)
I want to sort a field structure that is a vector field. You can see in the image.
I tried the following method but it doesn't works.
D=struct2cell(A) tam=size(D) D = reshape(D, tam(1), []) D=D' D=sortrows(D,1)
when I do the last command matlab error message apears:
Error using sortrows>sort_cell_back_to_front (line 130) Some cells in X contain non-scalar values and cannot be sorted.
Error in sortrows (line 88) ndx = sort_cell_back_to_front(x_sub, col);
I think it's because the first field is a vector field of type double.
How can I solve this?
Thanks in advance.

采纳的回答

Guillaume
Guillaume 2017-5-26
Assuming that you want to sort by antecedent
[~, order] = sortrows(vertcat(A.antecedent));
A = A(order)
  5 个评论
Guillaume
Guillaume 2017-5-29
@alfred, I don't understand what you mean by "I want that the column consequent change with the same rows of antecedent, because any row of antecedent have his consequent value". Can you show an example of input and desired output?
[~, order] = ...
the ~ means: I don't care about this output. You only want the second output of sortrows, the order of the indices.
alfred
alfred 2017-5-29
@Guillaume, Sorry how i said before i have seen that the consequent change with antecedent 1 by 1. then i answerd me...
And i don't understand totally your answer.. because... this function ordered with first output too... or is what it seems... i tried to put all disordered and it works correctly. always put [1 1] in the first row then what you mean with first output?
I'm really confused..

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by