Я решил сделать полную переписку, потому что оригинал слишком далек от моего собственного стиля, чтобы я мог отформатировать его, как свой собственный код.
Я не пытался это проверить, поэтому вполне возможно, что что-то сломалось, но я считаю, что большая часть этого правильна.
Я использую текстовые ячейки для описания синтаксиса моих функций. Я обычно встраиваю (* comments *)
для объяснения кода, но если объяснения становятся очень длинными, я также перемещаю их в текстовые ячейки.
Я включил комментарий, объясняющий func1
. Это не очень полезный комментарий, но он служит примером.
Вот изображение моего ноутбука с увеличением 75%:
Выражение ячейки для копирования и вставки:
Cell[CellGroupData[{Cell["Rewrite", "Subsection"],
Cell[TextData[{
StyleBox["distance", "Program"],
"[{",
StyleBox["x1",
FontSlant->"Italic"],
", ",
StyleBox["y1",
FontSlant->"Italic"],
"}] gives EuclideanDistance from {x1, y1} to global {centerX, \
centerY}\n",
StyleBox["distance", "Program"],
"[{",
StyleBox["x1",
FontSlant->"Italic"],
", ",
StyleBox["y1",
FontSlant->"Italic"],
"}, {",
StyleBox["x2",
FontSlant->"Italic"],
", ",
StyleBox["y2",
FontSlant->"Italic"],
"}] gives EuclideanDistance from {x1, y1} to {x2, y2}"
}], "Text"],
Cell[BoxData[
RowBox[{
RowBox[{"distance", "[",
RowBox[{"a_", ",",
RowBox[{"b_:",
RowBox[{"Hold", "@",
RowBox[{"{",
RowBox[{"centerX", ",", "centerY"}], "}"}]}]}]}], "]"}], ":=",
RowBox[{"EuclideanDistance", "[",
RowBox[{"a", ",",
RowBox[{"ReleaseHold", "@", "b"}]}], "]"}]}]], "Input"],
Cell[TextData[{
StyleBox["rejection", "Program"],
"[",
StyleBox["disp, fixation, durationLimit, minDistance",
FontSlant->"Italic"],
"]\n\nfilters data from ",
StyleBox["t4dataLAEH10", "Program"],
" according to:\n\t",
StyleBox["disp",
FontSlant->"Italic"],
" : (description of argument disp)\n\t",
StyleBox["fixation",
FontSlant->"Italic"],
" : (description of argument fixation)\n\t",
StyleBox["durationLimit",
FontSlant->"Italic"],
" : (description of durationLimit)\n\t",
StyleBox["minDistance",
FontSlant->"Italic"],
" : (description of minDistance)"
}], "Text"],
Cell[BoxData[
RowBox[{
RowBox[{"rejection", "[",
RowBox[{
"disp_", ",", "fixation_", ",", "durationLimit_", ",",
"minDistance_"}], "]"}], ":=", "\[IndentingNewLine]",
RowBox[{"Module", "[",
RowBox[{
RowBox[{"{",
RowBox[{"fakedata", ",", "num", ",", "func1"}], "}"}], ",",
"\[IndentingNewLine]",
RowBox[{"(*", " ",
RowBox[{"description", " ", "of", " ", "fakedata"}], " ", "*)"}],
"\[IndentingNewLine]",
RowBox[{
RowBox[{"fakedata", "=",
RowBox[{"consider", "[",
RowBox[{"t4dataLAEH10", ",", "9", ",", "disp", ",",
RowBox[{"{",
RowBox[{"17", ",", "18", ",", "11"}], "}"}]}], "]"}]}], ";",
"\[IndentingNewLine]", "\[IndentingNewLine]",
RowBox[{"(*", " ",
RowBox[{"description", " ", "of", " ", "num"}], " ", "*)"}],
"\[IndentingNewLine]",
RowBox[{"num", "=",
RowBox[{"Position", "[",
RowBox[{
RowBox[{
RowBox[{"fakedata", "\[LeftDoubleBracket]",
RowBox[{"All", ",", "3"}], "\[RightDoubleBracket]"}], "~",
"Take", "~", "fixation"}], ",",
RowBox[{"x_", "/;",
RowBox[{"x", ">", "durationLimit"}]}]}], "]"}]}], ";",
"\[IndentingNewLine]", "\[IndentingNewLine]",
RowBox[{"(*", " ",
RowBox[{
RowBox[{"func1", ":", " ",
RowBox[{
"Take", " ", "the", " ", "first", " ", "two", " ", "columns",
" ", "of", " ", "fakedata"}]}], ",", " ",
RowBox[{
RowBox[{
RowBox[{
"and", " ", "drop", " ", "rows", " ", "specified", " ", "by",
" ",
RowBox[{
StyleBox["dropspec",
FontSlant->"Italic"], ".", "\[IndentingNewLine]",
"Delete"}], " ", "any", " ", "rows", " ", "for", " ",
"which", " ",
StyleBox["distance", "Program"]}], " ", "<", " ",
StyleBox["minDistance",
FontSlant->"Italic"]}], ";", " ",
RowBox[{
"if", " ", "no", " ", "rows", " ", "are", " ", "deleted"}]}],
",", "\[IndentingNewLine]", " ",
RowBox[{
"return", " ", "the", " ", "first", " ", "two", " ", "columns",
" ", "of", " ", "fakedata"}], ",", " ",
RowBox[{"ignoring", " ",
RowBox[{"dropspec", "."}]}]}],
StyleBox[" ",
FontSlant->"Italic"], "*)"}], "\[IndentingNewLine]",
RowBox[{
RowBox[{"func1", "[", "dropspec_", "]"}], ":=",
RowBox[{"Module", "[",
RowBox[{
RowBox[{"{",
RowBox[{"part", ",", "fake"}], "}"}], ",",
"\[IndentingNewLine]",
RowBox[{
RowBox[{"part", "=",
RowBox[{"fakedata", "\[LeftDoubleBracket]",
RowBox[{"All", ",",
RowBox[{"{",
RowBox[{"1", ",", "2"}], "}"}]}],
"\[RightDoubleBracket]"}]}], ";", "\[IndentingNewLine]",
RowBox[{"fake", "=",
RowBox[{"part", "~", "Drop", "~", "dropspec"}]}], ";",
"\[IndentingNewLine]",
RowBox[{
RowBox[{
RowBox[{"If", "[",
RowBox[{
RowBox[{"#", "=!=",
RowBox[{"{", "}"}]}], ",",
RowBox[{"fake", "~", "Delete", "~", "#"}], ",", "part"}],
"]"}], "&"}], "@", "\[IndentingNewLine]",
RowBox[{"Position", "[",
RowBox[{
RowBox[{"distance", "/@", "fake"}], ",",
RowBox[{"x_", "/;",
RowBox[{"x", "<", "minDistance"}]}]}], "]"}]}]}]}],
"]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]",
RowBox[{"If", "[",
RowBox[{
RowBox[{"num", "=!=",
RowBox[{"{", "}"}]}], ",",
RowBox[{"func1", " ", "@", " ",
RowBox[{"num", "\[LeftDoubleBracket]",
RowBox[{
RowBox[{"-", "1"}], ",", "1"}], "\[RightDoubleBracket]"}]}],
",",
RowBox[{"func1", "@", "0"}]}], "]"}]}]}], " ",
"]"}]}]], "Input"]
}, Open ]]