ignoring return value syntax?

2020-03-24 04:32发布

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.

标签: matlab octave
2条回答
萌系小妹纸
2楼-- · 2020-03-24 05:10

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

查看更多
我命由我不由天
3楼-- · 2020-03-24 05:25

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.

查看更多
登录 后发表回答