问题
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:
Why does Octave not support this? (i.e. bug, future enhancement, design decision, etc.)
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