0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

MathematicaAdvent Calendar 2016

Day 1

Mathematicaで数表のハイライト

Last updated at Posted at 2016-12-01

便利なやつからいきます。

テーブルをグリッド表示する際、特定の条件式に当てはまるセルをハイライト表示します。

hilight-table.nb
highlightTable[tbl_, crit_, color_: Red] := 
 Grid[tbl] /. {n_?crit -> Item[n, Background -> color]}

例として、$x \times y - 1$ が素数となるセルを着色するコードを示します。

prime-q--x-times-y.nb
tbl = Table[x y - 1, {y, 10}, {x, 10}];
highlightTable[tbl, PrimeQ]

このように表示されます。

image

1行で書き下すと以下のようになります。

prime-q--x-times-y--one-line.nb
Grid[Table[x y - 1, {y, 15}, {x, 15}]] /. {n_?PrimeQ -> Item[n, Background -> Red]}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?