フィルターのクリア

How can I use tabs in legend text?

28 ビュー (過去 30 日間)
KAE
KAE 2017 年 8 月 18 日
回答済み: KAE 2017 年 8 月 18 日
I would like to use tabs in the text of a legend, but can't figure out how. I tried doing using sprintf (below), but the tabs aren't displayed. Is this because a legend is a listbox which apparently can't display tabs, and the only workaround is to use spaces instead? I am using R2015b.
figure;
x = 1:0.1:10;
y1 = sin(x*pi); % First variable to plot
y2 = cos(x*pi); % Second variable to plot
h1 = plot(x, y1, x, y2);
legendStr{1} = sprintf('First\t%4.2f',rand(1)); % First legend entry with tab
legendStr{2} = sprintf('Second\t%4.2f',rand(1)); % Second legend entry with tab
disp(legendStr) % Display the string to show it contains tabs as expected
legend(h1, legendStr, 'FontName', 'FixedWidth'); % But no tab appears in legend

採用された回答

KAE
KAE 2017 年 8 月 18 日
I was able to use detab as a workaround, but is there a more direct way?
legend(h1, detab(legendStr), 'FontName', 'FixedWidth'); % Now tab appears in legend

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by