Reputation: 153
We are given a cell array Ref_M
of size m x n, and a vector IND
of length m.
IND(i)
contains the number of non-empty cells in the i
th row of Ref_M
. The purpose is to organize the lines in the cell array Ref_M
based on the value in the IND
vector from the largest value to the smallest.
Given:
Ref_M = [2x2 double] [2x2 double] []
[2x2 double] [] []
[2x2 double] [2x2 double] []
[2x2 double] [2x2 double] [2x2 double]
IND = [ 2 1 2 3]
The result should be:
New_Ref_M = [2x2 double] [2x2 double] [2x2 double]
[2x2 double] [2x2 double] []
[2x2 double] [2x2 double] []
[2x2 double] [] []
Also, is there a method to organize the cell array Ref_M
lines without using the given vector of indexes, IND
?
Upvotes: 0
Views: 200
Reputation: 27201
Try sort()
.
[B, transform] = sort(IND, 'descend');
New_Ref_M = Ref_M(transform, :);
You can determine IND
on your own using:
IND = sum(~cellfun('isempty', Ref_M), 2);
Upvotes: 1