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 vue (au cours des 30 derniers jours)
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.

Réponse acceptée

Star Strider
Star Strider le 12 Sep 2015
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 commentaires
Pradeep Sathyanarayana
Pradeep Sathyanarayana le 12 Sep 2015
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 le 12 Sep 2015
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)

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by