ignoring return value syntax?

血红的双手。 提交于 2019-12-30 10:05:35

问题


In Matlab, the tilda symbol can be used to ignore a certain parameter from a function that returns multiple parameters. However, when I try the same code in Octave, I get a syntax error.

I have two questions:

  1. Why does Octave not support this? (i.e. bug, future enhancement, design decision, etc.)

  2. What's the alternative syntax in Octave, if any (without just putting a "dummy variable" into the spot then clearing that variable)? Additionally, is this alternative syntax Matlab compatible?


% this is valid Matlab code, but will result in a syntax error in Octave
[colA, colB, ~, colC] = textread('data.txt', '%d %d %s %d', 1);

Fyi, I'm using Octave 3.2.4 compiled for windows with some Octave Forge packages.


回答1:


This syntax was just introduced in one of the latest versions. So there is no expectation that Octave would match that feature.

Your alternatives are effectively to introduce dummy variables in some form. Here are the common choices used before ~ became an option.

[colA, colB, colC, colC] = textread('data.txt', '%d %d %s %d', 1);
[colA, colB, ans, colC] = textread('data.txt', '%d %d %s %d', 1);

I like the latter, as ans is what matlab uses anyway as a bit bucket.




回答2:


This feature was introduced in Octave 3.4. So the code should work with current builds of Octave.



来源:https://stackoverflow.com/questions/5177229/ignoring-return-value-syntax

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!