1

I'm putting text into an image and saving it to my computer in Matlab. I am using the following code to do so:

ha = axes('Position',[.25 0 .5 .25],'Xlim',[0 1],'Ylim',[0 1],'Box','off','Visible','off','Units','normalized', 'clipping' , 'off');
text(0.5, .9,'This is my subtitle',...
'center','VerticalAlignment', 'bottom', 'FontSize', 18)

Currently, it is printing out the 'this is my subtitle' line. However, I want to use user input to determine what that text is. I have at the beginning of the code:

prompt = 'What is the subtitle of your image? ' ;
mysubtitle = input(prompt, 's');

How can I code the text() line to print the mysubtitle input as the subtitle on the image?

Note: when I say:

text(0.5, .9, mysubtitle....)

It gives an error message (for use of the text function) of 'Invalid parameter/value pair arguments'.

2
  • Can't you just replace 'this is my subtitle' by mysubtitle in your call to text? Or maybe mysubtitle{1} i aleays forget if the output of prompt is a cell array Commented Dec 3, 2014 at 22:45
  • When I replace 'this is my subtitle' with mysubtitle, it gives the following error: Invalid parameter/value pair arguments When I replace it with mysubtitle{1}, it gives: Cell contents reference from a non-cell array object. Commented Dec 3, 2014 at 22:47

1 Answer 1

2

This is the solution:

prompt = 'What is the subtitle of your image? ' ;
mysubtitle = input(prompt, 's');

ha = axes('Position',[.25 0 .5 .25],'Xlim',[0 1],'Ylim',[0 1],'Box','off','Visible','off','Units','normalized', 'clipping' , 'off');
text(0.5,.9,mysubtitle,'HorizontalAlignment', 'center', 'VerticalAlignment', 'bottom', 'FontSize', 18)

Please make sure your example code is correct, makes it harder to answer. You had forgotten the 'HorizontalAlignment'!

Sign up to request clarification or add additional context in comments.

1 Comment

Wow! Thanks! I didn't realize that I inadvertently deleted that... :D :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.