strings in a loop

2 ビュー (過去 30 日間)
Sven Schoeberichts
Sven Schoeberichts 2011 年 11 月 17 日
Hi all,
I made up some code to put a piece of text in a figure. But at the moment it only supports 2 values. I need it to be in a loop, so I can get the values with Frr(i).
text( 0.97, 0.93, ...
[ '\fontsize{8}\color{blue}' ...
num2str(Frr(1)) ' Hz, ' num2str( Prr(1)), 10, ...
num2str(Frr(2)) ' Hz, ' num2str( Prr(2)), 10, ...
'EdgeColor','black', 'HorizontalAlignment', 'right', 'VerticalAlignment', 'top', 'Margin', 3, 'Units', 'normalized' );
I have been trying different things, like making strings and concatenating them together, but it becomes one long string.
I hope someone can help me.
Thanks in advance,
Gr. Sven
btw: the '10' in the code is the ascii code for a new line...
  1 件のコメント
Walter Roberson
Walter Roberson 2011 年 11 月 17 日
This is really a question about how to get a line break in TeX or LaTex.

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

採用された回答

Jonathan
Jonathan 2011 年 11 月 17 日
Sven,
In most Matlab functions that display text, you can pass a cell array of strings to accomplish new lines. The example below does this for the two case example you gave.
text( 0.97, 0.93, ...
{['\fontsize{8}\color{blue}' num2str(Frr(1)) ' Hz, ' num2str( Prr(1))], ...
['\fontsize{8}\color{blue}' num2str(Frr(2)) ' Hz, ' num2str( Prr(2))]}, ...
'EdgeColor','black', 'HorizontalAlignment', 'right', ...
'VerticalAlignment', 'top', 'Margin', 3, 'Units', 'normalized' );
To put this in a loop, try something like this.
Frr = randi(10,10,1);
Prr = randi(10,10,1);
strFun = @(x, y) ['\fontsize{8}\color{blue}' num2str(x) ' Hz, ' num2str(y)]
strCell = cell(size(Frr));
for i = 1:numel(Frr)
strCell{i} = strFun(Frr(i), Prr(i));
end
text( 0.97, 0.93, strCell, ...
'EdgeColor','black', 'HorizontalAlignment', 'right', ...
'VerticalAlignment', 'top', 'Margin', 3, 'Units', 'normalized' );
  1 件のコメント
Sven Schoeberichts
Sven Schoeberichts 2011 年 11 月 17 日
Your suggestion works perfectly, thanks Jonathan!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by