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.
2 次查看(过去 30 天)
显示 更早的评论
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!