1
$\begingroup$

I have two lists A and B, I am trying to change modify the elements of list A in an increasing order such that my list B should also be changed according to list A. The node no list is given below.  expected out put

nodeno = {1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,  19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 2, 33, 34, 35,     36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,
    53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68,     69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85,
    86, 87, 88, 89, 90, 91, 32, 93, 94, 95, 96, 97, 98, 99, 100, 101,     102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114,     115, 116, 117, 118, 119, 120, 121, 92};

A = {0.0000, 0.33333*^-001, 0.66667*^-001, 0.10000, 0.13333, 0.16667, 
   0.20000, 0.23333, 0.26667, 0.30000, 0.33333, 0.36667, 0.40000, 
   0.43333, 0.46667, 0.50000, 0.53333, 0.56667, 0.60000, 0.63333, 
   0.66667, 0.70000, 0.73333, 0.76667, 0.80000, 0.83333, 0.86667, 
   0.90000, 0.93333, 0.96667, 1.0000, 1.0333, 1.0667, 1.1000, 1.1333, 
   1.1667, 1.2000, 1.2333, 1.2667, 1.3000, 1.3333, 1.3667, 1.4000, 
   1.4333, 1.4667, 1.5000, 1.5333, 1.5667, 1.6000, 1.6333, 1.6667, 
   1.7000, 1.7333, 1.7667, 1.8000, 1.8333, 1.8667, 1.9000, 1.9333, 
   1.9667, 2.0000, 2.0333, 2.0667, 2.1000, 2.1333, 2.1667, 2.2000, 
   2.2333, 2.2667, 2.3000, 2.3333, 2.3667, 2.4000, 2.4333, 2.4667, 
   2.5000, 2.5333, 2.5667, 2.6000, 2.6333, 2.6667, 2.7000, 2.7333, 
   2.7667, 2.8000, 2.8333, 2.8667, 2.9000, 2.9333, 2.9667, 3.0000, 
   3.0333, 3.0667, 3.1000, 3.1333, 3.1667, 3.2000, 3.2333, 3.2667, 
   3.3000, 3.3333, 3.3667, 3.4000, 3.4333, 3.4667, 3.5000, 3.5333, 
   3.5667, 3.6000, 3.6333, 3.6667, 3.7000, 3.7333, 3.7667, 3.8000, 
   3.8333, 3.8667, 3.9000, 3.9333, 3.9667, 4.0000};

B = {0., 0.00667455, -0.000127735, -0.000253022, -0.000373416, \
-0.00048648, -0.000589791, -0.000680937, -0.000757529, -0.000817198, \
-0.000857599, -0.000876413, -0.000871348, -0.000840142, -0.000780558, \
-0.000690389, -0.000567452, -0.000409589, -0.00021466, 0.0000194606, 
   0.000294888, 0.000613737, 0.000978126, 0.00139019, 0.0018521, 
   0.00236604, 0.00293428, 0.00355913, 0.00424301, 0.00498843, 
   0.00579801, 0.00667455, 0.00806478, 0.0101464, 0.0128567, 
   0.0161336, 0.019915, 0.0241395, 0.0287463, 0.033675, 0.0388665, 
   0.0442623, 0.0498052, 0.0554396, 0.0611109, 0.0667666, 0.0723559, 
   0.0778301, 0.0831425, 0.0882489, 0.0931078, 0.0976802, 0.10193, 
   0.105824, 0.109332, 0.112428, 0.115087, 0.117291, 0.119022, 
   0.120268, 0.121019, 0.12127, 0.121019, 0.120268, 0.119022, 
   0.117291, 0.115087, 0.112428, 0.109332, 0.105824, 0.10193, 
   0.0976802, 0.0931078, 0.0882489, 0.0831425, 0.0778301, 0.0723559, 
   0.0667666, 0.0611109, 0.0554396, 0.0498052, 0.0442623, 0.0388665, 
   0.033675, 0.0287463, 0.0241395, 0.019915, 0.0161336, 0.0128567, 
   0.0101464, 0.00806478, 0., 0.00579801, 0.00498843, 0.00424301, 
   0.00355913, 0.00293428, 0.00236604, 0.0018521, 0.00139019, 
   0.000978126, 0.000613737, 0.000294888, 
   0.0000194606, -0.00021466, -0.000409589, -0.000567452, \
-0.000690389, -0.000780558, -0.000840142, -0.000871348, -0.000876413, \
-0.000857599, -0.000817198, -0.000757529, -0.000680937, -0.000589791, \
-0.00048648, -0.000373416, -0.000253022, -0.000127735};

With[{p = Ordering[ansysxaxis]}, A = A[[p]]; B = B[[p]];]

data = Transpose[{A, B}]
ListPlot[data, Joined -> True]
$\endgroup$
2
  • 1
    $\begingroup$ With A, B and nodeno from your edit, try ListPlot[Transpose[{A, B[[nodeno]]}], Joined -> True] $\endgroup$ – creidhne Nov 6 '20 at 0:28
  • $\begingroup$ worked thanks. I was sorting the wrong variable $\endgroup$ – acoustics Nov 6 '20 at 5:16
1
$\begingroup$
o = Ordering @ A;
data1 = Transpose[{A[[o]], B[[o]]}];

Alternatively,

data2 = SortBy[First] @ Transpose[{A, B}];

data1 == data2
 True
ListPlot[data1, Joined -> True]

enter image description here

$\endgroup$
5
  • $\begingroup$ I am also getting the same result, but the results of the Ansys software is smooth and there is no jump at x=3 $\endgroup$ – acoustics Nov 5 '20 at 8:31
  • $\begingroup$ @acoustics So maybe Ansys is not doing what you believe it is. In any case, this answers your OP. $\endgroup$ – anderstood Nov 5 '20 at 8:36
  • $\begingroup$ still not working, you can verify this by plotting before and after applying sorting $\endgroup$ – acoustics Nov 5 '20 at 11:49
  • $\begingroup$ @acoustics can you clarify what or how this is “not working”? $\endgroup$ – CA Trevillian Nov 5 '20 at 13:53
  • $\begingroup$ I have added expected out put in the OP. Given x coordinate, I am trying to plot the y values $\endgroup$ – acoustics Nov 5 '20 at 13:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.