0
$\begingroup$

We have N=45 lists as below ones (I am bringing some of them to show their ordering)

list[1]={{0.26, 3, 0}, {0.26, 4, 0}, {0.26, 5, 0}, {0.26, 6, 0.0445602}};

list[2]={{0.27, 3, 0}, {0.27, 4, 0}, {0.27, 5, 0.129654}, {0.27, 6, 0}};

list[3]={{0.28, 3, 0}, {0.28, 4, 0.00488254}, {0.28, 5, 0.124178}, {0.28, 6, 
  0}};

.
.

list[20]={{0.45, 3, 0.228627}, {0.45, 4, 0}, {0.45, 5, 0}, {0.45, 6, 0}};

..

list[45]={{0.7, 3, 0.362271}, {0.7, 4, 0}, {0.7, 5, 0}, {0.7, 6, 0}};

If n is 3,4,5,... (the middle value in each row of any list ) and considering two edge numbers of each row in any list we wish to reach:

extract[3]={{0.26,0},{0.27,0},{0.28,0}, .....,{0.7,0.36}};

extract[4]={{0.26,0},{0.27,0},{0.28,0.00488254}, .....,{0.7,0}};

extract[5]={{0.26,0},{0.27,0.129654},{0.28,0.124178}, .....,{0.7,0}};

extract[6]={{0.26,0.0445602},{0.27,0},{0.28,0}, .....,{0.7,0}};

and so on

By:

extract= {}; Do[AppendTo[extract, list[i]], {i, 1,45}];

we joined all of them. After that we do not know what should be done!

$\endgroup$
2
$\begingroup$

There are many ways to do this. Here's one. Here are your lists:

list[1] = {{0.26, 3, 0}, {0.26, 4, 0}, {0.26, 5, 0}, {0.26, 6, 0.0445602}};
list[2] = {{0.27, 3, 0}, {0.27, 4, 0}, {0.27, 5, 0.129654}, {0.27, 6, 0}};
list[3] = {{0.28, 3, 0}, {0.28, 4, 0.00488254}, {0.28, 5, 0.124178}, {0.28, 6, 0}};

Then, define

Clear@extract
extract[n_] := extract[n] = Flatten[Join[Cases[list[#], {a_, n, b_} :> {a, b}] & /@ Range[3]], 1]

Then:

extract[1]
extract[3]
(* {} *)
(* {{0.26, 0}, {0.27, 0}, {0.28, 0}} *)

For your case, change Range[3]] to Range[45] if there are 45 such lists.

$\endgroup$
  • $\begingroup$ @Inzo. Yeah: that's what it does. extract[1] returns {} because there are no 3's. extract[3] returns {{0.26, 0}, {0.27, 0}, {0.28, 0}}, as it should. $\endgroup$ – march Aug 2 '17 at 15:33

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.