How to save matrix as a "pretty print" image?

23 ビュー (過去 30 日間)
Josh
Josh 2024 年 5 月 4 日
編集済み: Rik 2024 年 5 月 4 日
I'm creating animations based on abelian sandpile models, where the sandpile heights (integers>0) are used as index values to convert the matrices into color images (ind2rgb). I would like to create companion animations that show the original data in indexed, matrix form, hence the ask for saving a matrix in "pretty print" format as an image. I'll probably use matrices that are at max 20x20; otherwise, I imagine it'll be hard to keep the "font size" of the numbers large enough.
Depending on the model size, the animations are upwards of 10,000+ frames, so I don't want to do any screenshots or manual saving, even for a smaller/more basic example. But it would be a similar result as screenshotting the matrix as viewed in either the Command Window or Variables workspace. Something like this but without needing the commands and label:
If there's not a quick solution/hack, I may have to go the route of building out a separate function to handle this, which might be fun too.
  2 件のコメント
Josh
Josh 2024 年 5 月 4 日
thank you so much <3

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

採用された回答

Rik
Rik 2024 年 5 月 4 日
編集済み: Rik 2024 年 5 月 4 日
Depending on your definition of pretty, you can use my text2im function. If you use sprintf, don't forget to transpose the array first (since matrices are column major, but text is generated row major).
  4 件のコメント
Josh
Josh 2024 年 5 月 4 日
Rik
Rik 2024 年 5 月 4 日
Happy to help. I was on mobile when I wrote the answer, so links are harder. But I'll edit my answer to include the link.

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

その他の回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by