1
$\begingroup$

I have a big list that contains many 3D- chains (set of points) and for each of them a polynomial. So the structure of my list is for example

list= {{m^2 + l^2 - 1, {{x1, y1, z1}, {x2, y2, z2}, ...}}, {l^3, {{x'1, y'1, z'1}, ...}} 

and so on.

Now I want to export all chains in a separate file which have either p1 or p2 as their polynomial. So in a if-loop the syntax would be like

If[
 list[[i]][[1]] === (p1 or p2), 
 Export["list_i.txt", multilist[[i]][[2]], "Table", "FieldSeparators" -> " "]
]

I want to avoid using loops, and I also don't know how to include the current value of i in the loop in the filename of the export-file.

Does anyone know how to do this without loops? Thanks a lot!

$\endgroup$
1
  • $\begingroup$ Have you tried Select and then Map Export on the preselected chains? $\endgroup$
    – BlacKow
    May 5, 2016 at 16:05

1 Answer 1

2
$\begingroup$

This might work for you:

selected = Select[list, First[#] === p1 || First[#] === p2 &];
MapIndexed[
  Export["list_" <> ToString[First@#2] <> ".txt", #1, "Table", "FieldSeparators" -> " "] &,
  selected[[All, 2]]
]

It would be best, however, if you had actual examples of your list and of the polynomials p1 and p2 for us to test our code on.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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