Put a cell into a title in plot

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

Hi Ivan,
ST = {"Plot1", "Plot2"}
subplot(2,2,1)
plot(data.TR_GRF_EVENTS{1})
hTitle = title(ST{1})
subplot(2,2,2)
plot(data.TR_GRF_EVENTS{2})
hTitle = title(ST{2})
This code will produce something like that (Its just data i had opened) and now you can loop through it.
or you can use the sgtitle() function for an overall title.
Barry
Ivan Mich
Ivan Mich 2020년 6월 3일
You know I would like to do it without subplot. My loop that makes the plots from my code creates 50 images. So I would like to create 50 images individually, and making it via a loop
Thank you anyway
Could you please post your code so i can get all the insight? I think you are just using the wrong function for the title. You can just uste title(St{i}) after you plot(...).
for i=1:1:50
plot(data(...));
title(St{i});
end
But you don´t need the St variable you could just make it like this (When the name is always the same but only the number changes):
for i=1:1:50
figure
plot(...)
title(['plot ' num2str(i)])
end
So the plots will be named plot 1 - 50.
Ivan Mich
Ivan Mich 2020년 6월 3일
편집: Ivan Mich 2020년 6월 3일
I have this file (data.txt), accordind to this the loop created. The numbers of this file are going from 10,20,...250.
my code is:
Sr=regexp(fileread('data.txt'), '\r?\n', 'split') .';
for i=1:size(St);
..........
figure
plot(x,y,'b')
title(%I don't know how to syntax here)
end
The point is that I want to pass the cell numbers are coming from "data.txt" to the line
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.
Ivan Mich
Ivan Mich 2020년 6월 3일
편집: Ivan Mich 2020년 6월 3일
Thank you !!!

댓글을 달려면 로그인하십시오.

답변 (1개)

dpb
dpb 2020년 6월 3일

0 개 추천

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

카테고리

질문:

2020년 6월 3일

편집:

2020년 6월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by