Using first input of a vector as figure title

Hello, I am trying to create a figure/plot and use the first data point as the title for my figure. Unfortunately, I'm not even close to having the correct syntax and I don't really know where to start. Hope you can help, Thanks.
data = ['mytitle' 1 2 3 4 5]
figure(1)
plot (data(2:6))
title(data(1))

 Accepted Answer

You can't really do data = ['mytitle' 1 2 3 4 5] literally in MATLAB.
data = {'mytitle' 1 2 3 4 5}
figure(1)
plot([data{2:6}])
title(data{1})

3 Comments

Yes, I am aware of that. Is there a way you might suggest?
The code in the answer is the way to do it. I would recommend though, not to combine the string with the numerical data in a cell array, just to provide a title for the plot.
Thanks, I see the change now. I didn't notice that you had changed the coding.

Sign in to comment.

More Answers (0)

Categories

Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!