How do I create a grid of squares with text labels inside each square?

10 ビュー (過去 30 日間)
dinesh tce
dinesh tce 2014 年 7 月 24 日
コメント済み: dinesh tce 2014 年 7 月 30 日
I'd like to make a grid full of squares, and label them with numbers. I don't want exact codes -- I just want to know how to proceed.

採用された回答

Matz Johansson Bergström
Matz Johansson Bergström 2014 年 7 月 24 日
There are a couple of ways to do this, it depends on whether you want to have adjacent squares or squares with space between them. I would go for the adjacent squares, because it is much simpler.
My solution would be to use pcolor and a colormap with gray(2) , so I get white cells with black lines between them. By using pcolor you could add color to your squares if you want. You just change your colormap range and argument to pcolor, see pcolor .
For the text I would simply use text in two nested for-loops, offsettting the text into the center of each cell. Note you will have to align the text using the argument 'horisontalalignment', for more information see text.
  1 件のコメント
dinesh tce
dinesh tce 2014 年 7 月 30 日
thank you matz..its very useful for beginners like me ,,,

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2014 年 7 月 28 日
If you have the Image Processing Toolbox, check out the checkerboard() function.

カテゴリ

Help Center および File ExchangeColormaps についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by