【问题标题】:Using variable as text() function output in matlab在matlab中使用变量作为文本()函数输出
【发布时间】:2014-12-03 22:21:32
【问题描述】:

我正在将文本放入图像中并在 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');

如何编码 text() 行以将 mysubtitle 输入打印为图像上的字幕?

注意:当我说:

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

它给出“无效参数/值对参数”的错误消息(用于文本函数)。

【问题讨论】:

  • 你不能在你的文本调用中用 mysubtitle 替换 'this is my subtitle' 吗?或者 mysubtitle{1} 如果提示的输出是元胞数组,我可能会忘记
  • 当我用 mysubtitle 替换 'this is my subtitle' 时,它给出了以下错误:无效的参数/值对参数当我用 mysubtitle{1} 替换它时,它给出:来自 a 的单元格内容引用非元胞数组对象。

标签: matlab text input


【解决方案1】:

这是解决方案:

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)

请确保您的示例代码是正确的,这使得它更难回答。您忘记了“水平对齐”!

【讨论】:

  • 哇!谢谢!我没有意识到我无意中删除了... :D :D
猜你喜欢
  • 2016-04-06
  • 1970-01-01
  • 2014-06-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多