Sort cells order according to their values?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Hi all,
I have a function produces a cell like this:
K>> otpt{:}
ans =
3 0
2 1
ans =
1 -1
4 -0.5
ans =
4 -0.5
3 0
In each cell, the first column are labels and second column are x-coordinate of nodes. The output is a division of [-1, 1] into a number of blocks. As you can see this example equals to
The labels remain fixed for the nodes, however each time the function gives different order of cells. Now whenever I get the output, I'd like to sort the order of cells from left to right, i.e. I want the output to be
K>> otpt{:}
ans =
1 -1
4 -0.5
ans =
4 -0.5
3 0
ans =
3 0
2 1
How can I do it? Thanks!
0 Commenti
Risposta accettata
Stephen
il 6 Set 2018
I'm not sure why your desired output is being spread over two function outputs, but I believe you should be using the "sort" function with the optional second output in this scenario.
syntax:
[B,IX] = sort(A)
In your scenario, I'll assume you can do the sort inside your function on a common variable. I'll call that variable "list". You want to sort the variables in the second column of the variable.
[B2,IX] = sort(list(:,2));
B1 = list(IX,1);
output = [B1,B2];
After that you can parse the variable "output" as necessary to get your multiple outputs.
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Shifting and Sorting Matrices in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!