2014-12-03 303 views
1

我把文本放入圖像並將其保存到我的電腦中。我使用下面的代碼可以這樣做:在matlab中使用變量作爲文本()函數輸出

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) 

目前,它打印出「這是我的副標題」行。但是,我想使用用戶輸入來確定文本是什麼。我在代碼的開頭:

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

我如何編寫文本()行打印mysubtitle輸入的圖像上的字幕?

注意:當我說:

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

它給出了一個錯誤消息(使用文本功能的)的「無效參數/值對參數」。

+0

你就不能更換「這是我的副標題」由mysubtitle在你的電話發送短信?或者可能是mysubtitle {1}如果提示的輸出是單元格陣列,則我會忘記 – 2014-12-03 22:45:19

+0

當我用mysubtitle替換'This is my subtitle'時,它會給出以下錯誤: 無效的參數/值對參數 當我替換它時與mysubtitle {1},它給出: 來自非單元格數組對象的單元格內容引用。 – Marissa 2014-12-03 22:47:56

回答

2

這是解決方案:

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) 

請確保您的示例代碼是正確的,就更難回答。你忘記了'水平對齊'!

+0

哇!謝謝!我沒有意識到我無意中刪除了......:D:D – Marissa 2014-12-03 22:54:16

相關問題