Ignoring return value syntax?

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

I have two questions:

  • Why doesn't Octave support this? (i.e. error, future improvement, design decision, etc.)

  • What is the alternative syntax in Octave if there is one (not just putting the dummy variable in the spot and then clearing this variable)? Also, is this alternative Matlab syntax 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 am using Octave 3.2.4, compiled for windows with some Octave Forge packages.

+4
source share
2 answers

This syntax was introduced in only one of the latest versions. Thus, there is no expectation that Octave will match this feature.

Your alternatives effectively implement dummy variables in one form or another. Here are common options that were 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, since ans is what Matlab uses anyway as a bit bucket.

+1
source

This feature was introduced in Octave 3.4. Therefore, the code should work with the current Octave lines.

+4
source

Source: https://habr.com/ru/post/1342081/


All Articles