How to add a string array on a chart?
4 ビュー (過去 30 日間)
古いコメントを表示
I would like to add 3 lines of text stored in a cell array to my chart, but failed to display it onto the chart.
MATLAB complained that "Cell array can contain only non-empty character vectors, string vectors, or numbers."
The implementation is like:
% point is a 1 x 6 string array
point = "4^1+1" "4^2+1" "4^3+1" "4^4+1" "4^5+1" "4^6+1"
txt = { sprintf('U0 = %.1f', U0), sprintf('Gamma = %.1f', gamma), ...
["Grid points = " point] };
xlim = get(gca,'xlim');
ylim = get(gca,'ylim');
% Add text to chart
text(xlim(1)*2, ylim(2)*0.01, txt, 'FontSize', 16);
Result:
Error using text
Cell array can contain only non-empty character vectors, string vectors, or numbers.
Error in assignment2 (line 76)
text(xlim(1)*2, ylim(2)*0.01, txt, 'FontSize', 16);
The content of 'txt' is:
txt =
1×3 cell array
{'U0 = -10.0'} {'Gamma = 1.0'} {1×6 string}
My question is, how to add a string array onto the chart?
or how to convert a string array to a string vector so that it satisfied the requirements of cell array?
Thanks in advance!
0 件のコメント
採用された回答
Ameer Hamza
2020 年 5 月 18 日
Try this
point = "Grid points = " + sprintf('4^%d ', 1:6);
txt = { sprintf('U0 = %.1f', 1), sprintf('Gamma = %.1f', 2), ...
point};
xlim = get(gca,'xlim');
ylim = get(gca,'ylim');
% Add text to chart
text(xlim(1)*2, ylim(2)*0.01, txt, 'FontSize', 16);
2 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!