I am trying to use this code to name the title of my figure (this is done in a loop). (strings stored in cell array are called ) However, when i do so, the numbers are always positioned in a wierd manner, almost like a subscript to the text.
1 回表示 (過去 30 日間)
古いコメントを表示
Pradeep Sathyanarayana
2015 年 9 月 12 日
コメント済み: Star Strider
2015 年 9 月 12 日
files = dir('*.mat');
for ie=1:length(files)
load(files(ie).name)
[path name exten]=fileparts(files(ie).name);
theconvert{ie}=cellstr(name);
figure;
plot(1:size(MSD_averaged,1),MSD_averaged,'o','Markersize',10, 'color',rand(1,3));
ylabel('Instantaneous MSD', 'FontSize',100);
xlabel('Track number', 'FontSize',100);
title(theconvert{ie}, 'FontSize', 30);
However, after using the code if a the string was called 'channel_1'. The title would come in such a manner that, 'channel' would look fine but '1' would look like a subscript. Any help is welcome. Thank you.
0 件のコメント
採用された回答
Star Strider
2015 年 9 月 12 日
In certain instances, MATLAB interprets an underscore (_) as a subscript. The easiest way to force it to treat the underscore as just that is to put a backslant (\) ahead of it: \_. Setting 'Interpreter','none' also works, but it also disables other TeX or LaTeX code from rendering.
2 件のコメント
Star Strider
2015 年 9 月 12 日
My pleasure.
Note that the print function prints or saves a figure object. The sprintf (and fprintf) functions print strings.
You have to address cells with curly braces {} to print the contents of specific cell elements. (The print functions don’t accept cell arguments because cells can contain anything.)
For example:
strc = {'This is a string in a cell.'};
Q1 = sprintf('%s', strc{1}) % Uses ‘{}’
Q2 = sprintf('%s', strc) % Without ‘{}’
Q1 =
This is a string in a cell.
Error using sprintf
Function is not defined for 'cell' inputs.
Error in WHITEBOARD (line 698)
Q2 = sprintf('%s', strc)
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Title についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!