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.

采纳的回答

Star Strider
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 个评论
Pradeep Sathyanarayana
Thank you Star Strider. That was quite helpful. If I may, I am having another issue using the strings from cell array with 'print'. It doesn't seem to be taking the strings from the same cell array that I am using for the figure title. Is there any reason why this would be happening?
Star Strider
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 CenterFile Exchange 中查找有关 Title 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by