简体   繁体   English

Octave:文本函数的下标?

[英]Octave: Subscripts for the text function?

I'm running Octave 5.1.0.我正在运行 Octave 5.1.0。 I try to reproduce the code on this page: https://octave.sourceforge.io/octave/function/text.html我尝试在此页面上重现代码: https : //octave.sourceforge.io/octave/function/text.html

For example, I try to reproduce Demonstration 3 there, ie this code:例如,我尝试在那里重现演示 3,即此代码:

 clf;
 axis ([0 8 0 8]);
 title (["1st title";"2nd title"]);
 xlabel (["1st xlabel";"2nd xlabel"]);
 ylabel (["1st ylabel";"2nd ylabel"]);
 text (4, 4, {"Hello", "World"}, ...
       "horizontalalignment", "center", ...
       "verticalalignment", "middle");
 grid on;

I get the following error message:我收到以下错误消息:

text( , ,, , , , ): subscripts must be either integers 1 to (2^63)-1 or logicals (note: variable 'text' shadows function) text( , ,, , , , ):下标必须是整数 1 到 (2^63)-1 或逻辑数(注意:变量 'text' shadows 函数)

I tried changing the code to:我尝试将代码更改为:

clf;
 axis ([0 8 0 8]);
 title (['1st title';'2nd title']);
 xlabel (['1st xlabel';'2nd xlabel']);
 ylabel (['1st ylabel';'2nd ylabel']);
 text (4, 4, 'Hello','horizontalalignment', 'center','verticalalignment', 'middle');
 grid on;

Then I get the following error message:然后我收到以下错误消息:

text(4...[x6]...): but text has size 1x39 (note: variable 'text' shadows function) text(4...[x6]...): 但文本大小为 1x39(注意:变量 'text' shadows 函数)

I'm a bit stumped as to how to solve this.我对如何解决这个问题有点困惑。 I also fail to reproduce other code with the text function.我也无法使用 text 函数重现其他代码。 I started running Octave a few weeks ago, so it wouldn't be impossible that my installation failed somehow.几周前我开始运行 Octave,所以我的安装以某种方式失败并非不可能。 Other functions work as expected though.不过,其他功能按预期工作。

I have installed the io and statistics packages.我已经安装了 io 和 statistics 包。 Can they interfer somehow?他们能以某种方式干扰吗?

Can anybody figure out what's going on?有人能弄清楚发生了什么吗?

The key is in the error message:关键在错误消息中:

note: variable 'text' shadows function注意:变量“文本”阴影功能

It means you have defined "text" as a variable in your workspace, and have assigned a value to it.这意味着您已将“文本”定义为工作区中的变量,并为其分配了一个值。

Therefore, now each time you try to access the text function, you are accessing your variable instead.因此,现在每次您尝试访问text函数时,您都在访问您的变量。

Clear your workspace (or just the text variable) and try again.清除您的工作区(或仅清除text变量)并重试。

PS.附注。 While this is not conventional practice, I personally tend to name all my non-function variables starting with a capital letter, to avoid name-clashes with functions, since most functions in octave start with a small letter.虽然这不是常规做法,但我个人倾向于以大写字母开头命名所有非函数变量,以避免与函数发生名称冲突,因为八度中的大多数函数都以小写字母开头。

In general, always check that a name is not taken before you assign something to that name, to avoid 'shadowing' as in this case.通常,在为该名称分配某些内容之前,请始终检查该名称是否未被采用,以避免在这种情况下出现“阴影”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM