Toady, I encountered a problem while trying to classify certain data.
I have the coordinates of six points.
data = {{0.349661, 0.380297}, {0.858156, 0.8442}, {0.906745, 0.171579},
{0.0847783, 0.277227}, {0.198453, 0.40206}, {0.941614, 0.347187}};
I want to perform some operation on the x coordinate. The operation is as follows. If the x coordinate in one of the following ranges
{{0.0423892, 0.141616}, {0.141616, 0.274057}, {0.274057, 0.603909},
{0.603909, 0.882451}, {0.882451, 0.924179}, {0.924179, 0.959049}}
The new x coordinate will have the value 1, 2, 3, 4, 5, 6 respectively.
I tried the following:
judge = {{0.0423892, 0.141616}, {0.141616, 0.274057}, {0.274057, 0.603909},
{0.603909, 0.882451}, {0.882451, 0.924179}, {0.924179, 0.959049}};
Which[Sequence @@
Flatten@Table[{judge[[i, 1]] < # < judge[[i, 2]] &, i}, {i, 1, 6}]] /@
data[[All, 1]]
However, it failed. I discovered the mistake was
Table[{judge[[i, 1]] < # < judge[[i, 2]] &, i}, {i, 1, 6}]
I got
{{judge[[i, 1]] < #1 < judge[[i, 2]] &, 1}, {judge[[i, 1]] < #1 < judge[[i, 2]] &, 2}, {judge[[i, 1]] < #1 < judge[[i, 2]] &, 3}, {judge[[i, 1]] < #1 < judge[[i, 2]] &, 4}, {judge[[i, 1]] < #1 < judge[[i, 2]] &, 5}, {judge[[i, 1]] < #1 < judge[[i, 2]] &, 6}}
rather than
{{judge[[1, 1]] < #1 < judge[[1, 2]] &, 1}, {judge[[2, 1]] < #1 < judge[[2, 2]] &, 2}, {judge[[3, 1]] < #1 < judge[[3, 2]] &, 3}, {judge[[4, 1]] < #1 < judge[[4, 2]] &, 4}, {judge[[5, 1]] < #1 < judge[[5, 2]] &, 5}, {judge[[6, 1]] < #1 < judge[[6, 2]] &, 6}}
Evaluate
. Or inject a value fori
usingWith
. $\endgroup$