sorting cell array ascending order and changing the values within the cell to positive

2 views (last 30 days)
I have got the following cell array. I want to put the cell array in ascending order in such a way that the [smallest numberx24 double] is listed first. I also want all the values inside each cell array to be listed as positive values. So how do I incorporate an abs function?
[ 52416x24 double] [ 51888x24 double] [ 51384x24 double] [ 50880x24 double] [ 50400x24 double] [ 49920x24 double] [ 49440x24 double] [ 48984x24 double] [ 48528x24 double] [ 48072x24 double] [ 47640x24 double] [ 47208x24 double] [ 46800x24 double] [ 46392x24 double] [ 45984x24 double] [ 45576x24 double] [ 45192x24 double] [ 44808x24 double] [ 44424x24 double] [ 44040x24 double] [ 43680x24 double] [ 43320x24 double] [ 42960x24 double] [ 42600x24 double] [ 42264x24 double] [ 41928x24 double] [ 41592x24 double] [ 41280x24 double] [ 40944x24 double] [ 40632x24 double] [ 40320x24 double] [174696x24 double] [169056x24 double] [163776x24 double] [158808x24 double] [154128x24 double] [149736x24 double] [145560x24 double] [141648x24 double] [137904x24 double] [134376x24 double] [131016x24 double] [127824x24 double] [124776x24 double] [121872x24 double] [119112x24 double] [116472x24 double] [113928x24 double] [111504x24 double] [109176x24 double] [106944x24 double] [104808x24 double] [102768x24 double] [100776x24 double] [ 98880x24 double] [ 97056x24 double] [ 95280x24 double] [ 93576x24 double] [ 91944x24 double] [ 90360x24 double] [ 88824x24 double] [ 87336x24 double] [ 85920x24 double] [ 84528x24 double] [ 83184x24 double] [ 81888x24 double] [ 80616x24 double] [ 79416x24 double] [ 78216x24 double] [ 77064x24 double] [ 75960x24 double] [ 74880x24 double] [ 73824x24 double] [ 72792x24 double] [ 71784x24 double] [ 70824x24 double] [ 69888x24 double] [ 68952x24 double] [ 68064x24 double] [ 67200x24 double] [ 66336x24 double] [ 65520x24 double] [ 64704x24 double] [ 63912x24 double] [ 63144x24 double] [ 62400x24 double] [ 61656x24 double] [ 60936x24 double] [ 60240x24 double] [ 59568x24 double] [ 58896x24 double] [ 58224x24 double] [ 57600x24 double] [ 56976x24 double] [ 56352x24 double] [ 55752x24 double] [ 55176x24 double] [ 54600x24 double] [ 54024x24 double] [ 53472x24 double] [ 52944x24 double] [174696x24 double] [174696x24 double]
  1 Comment
Jan
Jan on 12 Oct 2014
@AA: Do you see, that your question contains mainly information, which are confusing only? This pile of sizes does not matter. It is not useful for understanding the problem or for solving it.

Sign in to comment.

Accepted Answer

Stephen23
Stephen23 on 10 Oct 2014
Edited: Stephen23 on 10 Oct 2014
Try this:
>> A = {rand(2,3)-0.5,rand(1,3)-0.5,rand(3,3)-0.5};
>> [~,X] = sort(cellfun('size',A,1));
>> B = cellfun(@abs,A(X),'UniformOutput',false);
The cell array A represents your cell array, it contains three numeric arrays, with size Nx3 for N=[1,2,3]. The first cellfun measures the size of the first dimension of each numeric array, these sizes are then sorted into order, returning the sort index. Then the second cellfun sorts the cell array according to this index, and takes the absolute value of the numeric arrays.
  2 Comments
AA
AA on 10 Oct 2014
thanks, how can i change this command B = cellfun(@abs,A(X),'UniformOutput',false); to get only the absolute value without the sorting?
Stephen23
Stephen23 on 11 Oct 2014
Edited: Stephen23 on 11 Oct 2014
If you only need the absolute value, without the sorting, then you can just use the same line of code, but without the indexing:
B = cellfun(@abs,A,'UniformOutput',false);
Your original question states that you need to sort the cell array, but now you request it unsorted. Is this the solution that you require?

Sign in to comment.

More Answers (0)

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!