Print user-defined error messages as a table

4 ビュー (過去 30 日間)
Jesus Sanchez
Jesus Sanchez 2019 年 12 月 6 日
コメント済み: Jesus Sanchez 2019 年 12 月 6 日
Hello all,
I would like to display an error message that informs the user of a function of the options that he has avaliable. Although its possible to print it in a straight line, I would like to write them as a table, because it looks prettier :)
So far I have this:
error_msg = ['Polygon not supported. List of supported polygons is:', ...
' Triangle Square Pentagon Hexagon Heptagon Octagon'];
error(error_msg);
This throws the error message:
-> Polygon not supported. List of supported polygons is: Triangle Square Pentagon Hexagon Heptagon Octagon.
I would like to show it like (the bullets do not matter, I just wrote them here for formatting):
-> Polygon not supported. List of supported polygons is:
  • Triangle
  • Square
  • Pentagon
  • Hexagon
  • Heptagon
  • Octagon
Is this possible to do? Thanks in advance!

採用された回答

Adam Danz
Adam Danz 2019 年 12 月 6 日
編集済み: Adam Danz 2019 年 12 月 6 日
msg = sprintf(['Polygon not supported. List of supported polygons is:\n' ...
' Triangle\n Square\n Pentagon\n Hexagon\n Heptagon\n Octagon']);
error(msg) %#ok<SPERR>
The key is to use line breaks in the error message. I've done this using sprintf() along with \n to indicate a line break.
Another method is to use newline() within a character or string array.
msg = ['Polygon not supported. List of supported polygons is:', newline(), ...
'Triangle',newline(),'Square',newline(),'Pentagon',newline(),...
'Hexagon',newline(),'Heptagon',newline(),'Octagon'];
  1 件のコメント
Jesus Sanchez
Jesus Sanchez 2019 年 12 月 6 日
Thanks! I messed up and wrote "/n" instead of "\n" when I tried to do it with like breaks, so I was quite confused

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by