# Problem with Select and Pick

I want to filter a data file choosing those elements that match a condition and then plot them. Here is the corresponding code I use:

data = Import["data.out", "Table"];
pick[m_List, i_Integer] := Module[{s = m[[i, 8]]}, Pick[m, s, s != 0]];
dataP = Table[{PointSize[0.005], Red, pick[data, i],
Point[{data[[i, 3]], data[[i, 4]], data[[i, 5]]}]}, {i, 1, Length[data]}]


The module pick is supposed to choose those elements from the list m for which $s\neq 0$. However, it does not work and therefore all the elements of the list are plotted. I used also Select[m, s !=0] but with no success. What am I doing wrong?

This is a small sample of the data file

data1={{-4.05, -0.48, -1.4648, -1.36804, -1.7282, 648.01, 1.03023*10^-13, 7},
{-4.05, -0.41, -1.2762, 1.7369, 1.55982, 278.54, 1.99574*10^-14, 0},
{-4.05, -0.34, -1.54191, 1.42069, 1.59888, 178.32, 9.0609*10^-14, 5}}

-

You should always try to provide a sample data. Since I don't know what you're trying to get with m[[i, 8]]. Note that both m and s must have the same Length for Pick to work.

You're using Pick wrong. Pick expects a pattern for it's third argument and you haven't provided one. Do this instead:

   filered = Pick[data1, data1[[All, 8]], x_ /; x != 0]

(* {{-4.05, -0.48, -1.4648, -1.36804, -1.7282, 648.01, 1.03023*10^-13, 7},
{-4.05, -0.34, -1.54191, 1.42069, 1.59888, 178.32,   9.0609*10^-14, 5}} *)


OR you can use Select as follows:

Select[data1, #[[8]] != 0 &]


OR

DeleteCases[data1, {x__, 0}]


Now you can proceed to plot the filtered data.

plotpoints = filtered[[All, {3, 4, 5}]]


{{-1.4648, -1.36804, -1.7282}, {-1.54191, 1.42069, 1.59888}}

Now using one of the 3D plot options that accepts data points should be all you need.

-
I posted a small sample of the data file. I want to choose all the items that have nonzero last element. – Vaggelis_Z Oct 12 '13 at 9:11
s = m[[i,8]] is the element of the last (eight) column. – Vaggelis_Z Oct 12 '13 at 9:16
The target is to read the external file, exclude all lines with zero eighth column and then create a 3D plot of the third, fourth and fifth elements of that lines. – Vaggelis_Z Oct 12 '13 at 9:20
@Vaggelis_Z. See my edit. Does this do what you want? – RunnyKine Oct 12 '13 at 9:22
Yes it does. But the question remains unsolved. Now, we just bypassed the problem. How can Select work right inside my original module? – Vaggelis_Z Oct 12 '13 at 9:32

Just to illustrate some options:

op1 = Cases[data1, Except[{__, 0}]];
op2 = Select[data1, #[[8]] != 0 &];
op3 = Pick[data1, (#[[8]] != 0 & /@ data1), True];
op1 == op2 == op3;
{Red, Point[#]} & /@ op1[[;; , {3, 4, 5}]]


Note the equlaity test is true. I hope I am interpreting correctly that R^3 point is aimed to be plotted.

-