多行注释:num2str 的问题 [英] Multiline annotation: problem with 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) 如何解决?(副载波数 = 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] )
推荐答案
按原样,您创建了一个由字符数组(字符串")组成的元胞数组,当在 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屋!