Marissa
Marissa

Reputation: 385

Using variable as text() function output in matlab

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'.

Upvotes: 1

Views: 702

Answers (1)

Ruben
Ruben

Reputation: 90

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'!

Upvotes: 2

Related Questions