Put a cell into a title in plot

21 次查看(过去 30 天)
Ivan Mich
Ivan Mich 2020-6-3
编辑: Ivan Mich 2020-6-3
Hello,
I have a code that creates some calculations and finally exports multiple plots(images). I would like for each one plot to create a title which will contain some numbers from a file. The file I mentioned is 25x1 cell.
To sum up, I would like for each plot the title to be: plot1, plot2, ... plot25
I have tried :
suptitle('plot',cellstr(St{i}))
and
suptitle('plot',char(St{i}))
but I did not make it.
Could you help me?
  6 个评论
Barry
Barry 2020-6-3
Sr=regexp(fileread('data'), '\r?\n', 'split') .';
for i=1:size(St);
..........
figure
plot(x,y,'b')
title(['Plot ', Sr{i}])
end
I also would use the readmatrix('data') function instead of this regexp function.
But this should do the trick. You have to use the String concat [ ... ] expression to concatenate the Plot and the number together.

请先登录,再进行评论。

回答(1 个)

dpb
dpb 2020-6-3
Sr=regexp(fileread('data.txt'), '\r?\n', 'split') .'; % reads as a string, not numeric
for i=1:size(St); % size() returns a 2-vector; what's St ???
..........
Presuming one of the St or Sr variables above is a typo,
Sr=importdata('data.txt'); % read the data as numeric, not text...
for i=1:numel(Sr)
..........
figure
plot(x,y,'b')
title(compose('Plot: %d',Sr(i))) % num2str or sprintf work, too...
end

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by