How to insert a variable and datetime array into a graph title?

9 次查看(过去 30 天)
I have a graph that I want to include the date&time it was made and the number of data stacks the plot contains on it. The number of stacks is a variable that changes depending on what I input for it. The title for the plot works when I use:
but I also want to add "Number of stacks: N" to the title.
I have this so far but it isn't working:
sgtitle('Recorded on: ', [datestr(startTime)],'Number of Stacks: ',N)
I want the title to look like this:
Recorded on: dategoeshere, Number of Stacks: N


Star Strider
Star Strider 2022-3-2
It would be easier to use datetime than earlier date versions —
N = 4;
for k = 1:N
plot((1:5), randn(1,5))
title(sprintf('Subplot #%d',k))
sgtitle(sprintf('Recorded on: %s, Number of Stacks: %d', datetime('now'),N))
See the documentation for sprintf for its details.
  2 个评论


更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by