Questions tagged [sorting]

Questions on the sorting/ordering functions of Mathematica (Sort, SortBy, Ordering, etc.).

Filter by
Sorted by
Tagged with
4 votes
2 answers
276 views

Sorting a list of "Low", "Medium", "High" into low, medium, high

I have a list with 10.000 entries containing "low", "medium" & "high" data. It is in random order. How can I sort that to low, medium high?
user avatar
  • 43
4 votes
2 answers
116 views

Extracting the second largest and minimum values, and plot

How to extract the second lowest and the second largest values of each row, and plot them as upper and lower graphs? I try with TakeLargest (or ...
user avatar
  • 173
1 vote
1 answer
49 views

Sorted Tuples without Filtering

Say I have a list $L$ where the elements can be sorted into some canonical order. I want to use Tuples[L,m] but I only want the output lists to be sorted and ...
user avatar
4 votes
2 answers
84 views

Tuples which treats re-ordering as equivalent [duplicate]

I would like to define a new function myTuples, that behaves just like Tuples, except that it treats, as with ...
user avatar
  • 951
2 votes
1 answer
92 views

Re-sorting higher-order ordinary differential equations

I have some higher-order ordinary differential equations. Firstly, I want to collect the terms with common factors together. Besides, I want to re-sort the ODE with the highest order term first. How ...
user avatar
0 votes
0 answers
44 views

How to make a poker sort function?

I am working on a Poker program. I have two hands in the form of two lists with five strings each. Each string is has a value of 2,3,4,5,6,7,8,9,T,J,Q,K,A concatenated to a suit of C,D, H, S. Here is ...
user avatar
1 vote
1 answer
50 views

How to sort a list of strings in alphabetical order? [closed]

I have a list of strings: listOfStrings = {"dog", "zebra", "donkey", "anteater", "fish"}; How do I sort them in ...
user avatar
1 vote
1 answer
62 views

How to sort a "+" sequence and get back a new sequence of "+" sorted? [closed]

How to sort a "+" sequence like 1+5+3+2+4 to get back 1+2+3+4+5 Same sorting problem with polynoms (but I am mainly ...
user avatar
6 votes
4 answers
196 views

How to order the coordinates generated by ToBoundaryMesh counterclockwise?

The following code works for polygons. A square 4x4 is tried here: ...
user avatar
1 vote
1 answer
84 views

Sort polynomial by monomial degree [closed]

there is an equation : z = a^2 + a b + a a' + a a' a'' + a b' and i want to rearrange the equation by sorting the terms by number of variable multiplication within. If my English is not well, let me ...
user avatar
  • 61
5 votes
2 answers
196 views

Sorting Cartesian coordinates

Here is the problem: I create a coordinate list as follows: ...
user avatar
2 votes
2 answers
125 views

Sorting pairs of approximate numbers

In an ideal world I would have: list1 = {{2, 0}, {2, -1}, {2, 0}, {2, -1}}; Sort[list1] {{2, -1}, {2, -1}, {2, 0}, {2, 0}} while in the real world I have: ...
user avatar
  • 181
2 votes
1 answer
319 views

Using < or <= make different results when sort

...
user avatar
  • 2,451
2 votes
1 answer
34 views

Arrange an expression based on variables' names

I have a problem of arranging an expression as shown in the following picture. The first expression exp is derived from other functions and equations. I want to get ...
user avatar
  • 663
1 vote
2 answers
76 views

Arrange an expression based on functions' names

I have a problem of arranging an expression as shown in the following picture. The first expression disorderF is derived from other functions and equations, which ...
user avatar
  • 663
2 votes
2 answers
117 views

For a given set, how to get rid of the some particular set?

Consider the following decomposition list of $\{a1,a2,a3,a4\}$ into three parts as $t$, t={{{a1, a2}, {a3}, {a4}}, {{a1}, {a2, a3}, {a4}}, {{a1}, {a2}, {a3, a4}}, {{a1, a2}, {a4}, {a3}}, {{a1}, {a2, ...
user avatar
  • 335
5 votes
1 answer
126 views

Sorting colors in the plotstyle versus the grade of details [closed]

We have multi plots in a figure that are shown individually with specific colors. ...
user avatar
  • 4,647
5 votes
3 answers
192 views

How to manipulate the colours when joining points in ListPlot

Suppose I plot out two sets of data on the same graph as follows: ListPlot[{{{1, 1}, {2, 2}, {4, 4}}, {{3, 3}, {5, 5}, {6, 6}}}] The colours of the points change ...
user avatar
  • 755
2 votes
2 answers
59 views

Partially Orderless Arguments in Functions

I am a Mathematica beginner and I'm trying to implement a function of type f[i1_,i2_,i3_,i4_] such that it is orderless in the first two arguments and in the last ...
user avatar
9 votes
1 answer
178 views

How to sort lines into continous paths efficiently

As part of my work I get a bunch of lines from my co-worker. (Background: I do electromagnetic designs, my co-worker does the mechanical design). These lines are in random order, but I need them in ...
user avatar
  • 923
5 votes
1 answer
161 views

Conditional sorting of columns in a matrix

I have a matrix with ten columns, and I want to rearrange these columns with three conditions. Column 1+2n and 2+2n (0<=n=<4) always remain together and in the same order (1+2n before 2+2n). ...
user avatar
  • 973
0 votes
2 answers
63 views

How do you sort a list based on conditions? [closed]

If i have an list that ranges from 1 - 100. How can i sort elements from the list. For example i want elements that has greatest common divisor 1 with the number 24.
user avatar
5 votes
3 answers
434 views

How to sort first two numbers in sublists

Given t7 = t8 = {{3, 5, 1}, {19, 2, 9}, {4, 3, 1}, {19, 0, 8}}; I want to Sort the first two numbers in each sublist and keep ...
user avatar
  • 2,020
1 vote
2 answers
72 views

Rearrange a matrix with new Table Headings-List

I have used a procedure to rearrange my data in a more appropriate way for data analysis such that more similar elements lie next to each other and dissimilar ones far apart. Let's say I have a 5x5 ...
user avatar
  • 53
2 votes
1 answer
59 views

How to sort arguments in descending order in an orderless function

If I define an operator to be orderless SetAttributes[CirclePlus,Orderless] It puts the arguments into canonical sorting, i.e. ...
user avatar
0 votes
1 answer
67 views

Does default 'Sort' generate always the same result? [closed]

Does default 'Sort' output always the same result regardless if we change its order? Suppose that L = {E1,E2,E3,E4,E5} (*here E1,..,E5 means any possible ...
user avatar
  • 2,451
5 votes
2 answers
156 views

"Ordering " command gives different order when n=1 vs n=2?

Heres an MWE ...
user avatar
10 votes
4 answers
385 views

How to use Intersection[] but keep the original list order

I want to keep the original order of l1: ...
user avatar
3 votes
4 answers
63 views

Making function $S$ such that inputs as an list $\{1,3,2,4, \}$ and produces $s_{1234}$

I want to make $S[\{,\cdots, \}]$ as follows First input of $S$ is given list $\{1,2,3,\cdots, n\}$ and it produces $s_{123\cdots n}$ Further, if the ordering of the list is given differently, still ...
user avatar
  • 335
2 votes
3 answers
91 views

Swapping items in a table

I have a code that generates various tables like ...
user avatar
  • 295
6 votes
1 answer
85 views

Undesired side effect of SortBy [duplicate]

After long searching, I noticed that the SortBy[list,f] function has an annoying side effect: If the function f yields the same value for consecutive elements of the list, those are still sorted using ...
user avatar
  • 1,196
0 votes
1 answer
57 views

How to obtain the grouped separate line curves from the disorder data?

The sample point data and codes are listed as following. The point-image tells us that the data can be divided into nine groups. However, why are they divided into two groups by ...
user avatar
  • 663
0 votes
1 answer
65 views

Defining elements of matrix as a function of two variables (the position $(i,j)$ ) [closed]

I have the following array, which generated from grayscale image data,: $$ \left( \begin{array}{cccccccc} 162 & 162 & 162 & 161 & 162 & 157 & 163 & 161 \\ 162 & 162 &...
user avatar
  • 39
10 votes
1 answer
327 views

On the ordering of the vertices of a polygon

Writing: pts = {{1, 0}, {2, 0}, {2, 3}, {3, 3}, {3, 4}, {0, 4}, {0, 3}, {1, 3}, {1, 0}}; Graphics[{Red, Point[pts], Blue, Line[pts]}] we get: and all of this ...
user avatar
  • 181
1 vote
0 answers
47 views

Mismatch for Ordering[list,1] and Position[list, Min[list]] [closed]

I am using Ordering[list, 1] to get the position of the minimum of a list, but in this example ...
user avatar
  • 528
6 votes
3 answers
178 views

Combine SortBy with ReverseSortBy

Suppose I have a dataset, which I want to sort according to two criteria. However, I want the first criteria to be sorted ascending, and the second descending. This would require to somehow combine ...
user avatar
4 votes
1 answer
103 views

how to sum a column after SortBy[...]

Given a dataset: ...
user avatar
  • 4,391
1 vote
1 answer
50 views

l,r-operations on words $[[[1,2],3],4] \cdots, n]$, $[1,[2,[3,\cdots, [n-1,n]\cdots ]]]$

Suppose I have a word $\{1,2\}$, then $l(\{1,2\}) = \{[1,2]\} = \{1,2\} - \{2,1\}:=12-21$ and for the word with length $3$, (I will omit bracket), the $l$-operation is defined as $ l(1,2,3) = [[1,2],3]...
user avatar
  • 335
4 votes
1 answer
82 views

Concise way to do lexicographic ordering

I want to order a bunch of number sequences lexicographically. Did this with ...
user avatar
2 votes
1 answer
24 views

ordered set inclusion 2

Slightly change the previous question, ordered set inclusion, Now, consider $A=\{2,3\}$ and $B=\{2,3,4,5\}, C=\{5,2,4,3\}$, Now I want to make element $\{2,3\}$ is in $B$ as well as $C$, what can be ...
user avatar
  • 335
2 votes
2 answers
69 views

How to reorder {x,y} list data and plot as ListLinePlot

How to re-arrange data to find line plot in order (I tried with given below code). ...
user avatar
1 vote
1 answer
53 views

Sorting a Dataset by an enumerated column with assigned values

A $\mathtt{Dataset}$ has a column $C$ with enumerated values $c_i$, to each of which a number $n_{c_i}$ is manually assigned. The $\mathtt{Dataset}$ needs to be sorted based on the numbers. MWE: ...
user avatar
  • 1,950
6 votes
2 answers
179 views

Stop Canonical Ordering of Output List

I'm working with the code below, which works well for my purposes; however, instead of the canonical ordering seen in the output, I want the output produced in the order I give in the Cases line of ...
user avatar
  • 1,039
1 vote
0 answers
65 views

How can I sort in increasing order? [closed]

...
user avatar
  • 155
8 votes
6 answers
285 views

How to sort and extract a list containing products

I've some difficulties with lists containing products as elements, e.g. list = {A B A, A K B, A K R}, where A and B are from the same 'family', let's call it sector ...
user avatar
0 votes
1 answer
97 views

How do I ensure the substitution happens after I take the first derivative before taking my second derivative

The title may be a little confusing so let me explain what I mean: I am using lagrange brackets to produce some equations of motion for orbital mechanics, where the motion is split between oscillating ...
user avatar
5 votes
4 answers
175 views

How do I reorder and combine sublists based on sublist rankings given by another list?

I have two lists: ...
user avatar
  • 161
4 votes
2 answers
180 views

How do I sort points {ai,bi}; i = 1,2,....,N so that immediate successors are closest?

Suppose there are points {ai,bi}; i = 1,....,N, but this is given in some jumbled order such as ...
user avatar
-2 votes
1 answer
61 views

Sorting of eigensystem accroding to specific eigenvector

I have a matrix, I want to sort it with respect to specific eigenvectors. Here, I provided an example of a matrix HT: ...
user avatar
  • 139
2 votes
2 answers
103 views

Print function value at specified coordinate

Below is the code to evaluate the function. I am trying to print the function values at a specified coordinate as shown in ActCoor. ...
user avatar

1
2 3 4 5
8