多行注释:num2str问题 [英] Multiline annotation: problem with num2str

查看:174
本文介绍了多行注释:num2str问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望文本框中的文本显示为:

I expect the text in the textbox to show up as:

Simulation parameters: 
Number of loops = 500
Number of subcarriers = 12
Number of frames = 5,
MT = 2, MR = 2               % or MR x MT = 2 x 2

我的代码写为:

txt = {'Simulation parameters: ','Number of loops = ',  num2str(loops_num),'Number of subcarriers = ',num2str(Nfft),,'Number of frames = ',num2str(K),'MT = ',num2str(MT),'MR = ',num2str(MR)};
text(4,0.5,txt,'FontSize',12)

然后我得到了

1)如何解决? (Number of subcarriers = 100等必须在一行上)

1) How to fix it? (Number of subcarriers = 100, etc need to be on one line)

2)在这种情况下如何使用annotation?

2) How can I use annotation in such a case?

plot(1:10)
str = {'Simulation parameters: ','Number of loops = ',  num2str(loops_num),'Number of subcarriers = ',num2str(Nfft),'MT = ',num2str(MT),'MR = ',num2str(MR),'Number of frames = ',num2str(K)};
annotation( 'textbox', 'String',str, 'Color', 'black', ...
            'FontSize', 14, 'Units', 'normalized', 'EdgeColor', 'none', ...
            'Position', [0.8,0.5,0.2,0] )
set( gca, 'Position', [0.1, 0.1, 0.6, 0.8] )

推荐答案

按原样,您将创建一个char数组(字符串")的单元格数组,当在annotation中使用时,该数组将解释为单独的行.因此,您必须将这些值连接起来,这些值必须通过使用[ ... ]合并到一行.请参见以下简短示例:

As is, you create a cell array of char arrays ("strings"), which is interpreted as separate lines when used in annotation. So, you have to concatenate those values, which you want to have to be merged to one line by using [ ... ]. See the following short example:

plot(1:10);
str = { ...
  'Simulation parameters: ', ...
  ['Number of loops = ', num2str(500)], ...
  ['Number of subcarriers = ', num2str(12)], ...
  ['MT = ', num2str(2)], ...
  ['MR = ', num2str(2)], ...
  ['Number of frames = ', num2str(5)] ...
};
annotation('textbox', [0.3, 0.6, 0, 0], 'String', str, 'FitBoxToText', 'on');

输出(Octave 5.1.0;代码也在MATLAB Online中进行了测试)如下:

The output (Octave 5.1.0; code also tested in MATLAB Online) looks like this:

希望有帮助!

编辑:在这个问题上,注释是否可以移到图形外部. 有可能合并了对图形属性的操纵.那是修改后的代码:

On the question, if the annotation could be moved outside the figure. It's possible, BUT incorporates manipulating the figure properties. That's the modified code:

plot(1:10);
set(gca, 'Position', [0.1 0.1 0.6 0.8]);
str = { ...
  'Simulation parameters: ', ...
  ['Number of loops = ', num2str(500)], ...
  ['Number of subcarriers = ', num2str(12)], ...
  ['MT = ', num2str(2)], ...
  ['MR = ', num2str(2)], ...
  ['Number of frames = ', num2str(5)] ...
};
annotation('textbox', [0.75, 0.60, 0, 0], 'String', str, 'FitBoxToText', 'on');

这是更新的输出:

这篇关于多行注释:num2str问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆