Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

Commonmark migration
Source Link

#Using argument list:

Using argument list:

Octave is capable to get default arguments so expressions can be evaluated in the argument list.

This feature is useful when we want to compute an expression and use it multiple times:

f = @(x,a=sort(x))a(a>.5);

One use case is when we use an indexed assignment to modify part of an array and we want to use the array:

a=[1 2 3 4]
a(2)=5;

But the expression (a(2)=5) returns a(2), or the expression (a([1 3])=4) returns a two elements array. Neither returns the whole array. We can use the argument list:

f=@(a=[1 2 3 4],b=a(2)=5)a;

Here the result of the indexed assignment is stored into a dummy variable b and the function returns the array.

#Using argument list:

Octave is capable to get default arguments so expressions can be evaluated in the argument list.

This feature is useful when we want to compute an expression and use it multiple times:

f = @(x,a=sort(x))a(a>.5);

One use case is when we use an indexed assignment to modify part of an array and we want to use the array:

a=[1 2 3 4]
a(2)=5;

But the expression (a(2)=5) returns a(2), or the expression (a([1 3])=4) returns a two elements array. Neither returns the whole array. We can use the argument list:

f=@(a=[1 2 3 4],b=a(2)=5)a;

Here the result of the indexed assignment is stored into a dummy variable b and the function returns the array.

Using argument list:

Octave is capable to get default arguments so expressions can be evaluated in the argument list.

This feature is useful when we want to compute an expression and use it multiple times:

f = @(x,a=sort(x))a(a>.5);

One use case is when we use an indexed assignment to modify part of an array and we want to use the array:

a=[1 2 3 4]
a(2)=5;

But the expression (a(2)=5) returns a(2), or the expression (a([1 3])=4) returns a two elements array. Neither returns the whole array. We can use the argument list:

f=@(a=[1 2 3 4],b=a(2)=5)a;

Here the result of the indexed assignment is stored into a dummy variable b and the function returns the array.

Grammar / spelling / typo fixes
Source Link
Kevin Cruijssen
  • 136.2k
  • 14
  • 154
  • 394

#Using argument list:

Octave is capable to get default arguments so expressions can be evaluated in the argument list.

This feature is useful when we want to compute an expression and use it multiple times:

f = @(x,a=sort(x))a(a>.5);

One use case is when we use an indexed assignment to modify part of an array and we want to use the array:

a=[1 2 3 4 ]4]
a(2)=5;

But the expression (a(2)=5) returns a(2) no the whole array, or the expression (a([1 3])=4) returnareturns a two elements array. Neither returns the whole array. We can use the argument list:

f=@(a=[1 2 3 4],b=a(2)=5)a;

Here the result of the indexed assignment is stored into a dummy varablevariable b and the function returns the array.

#Using argument list:

Octave is capable to get default arguments so expressions can be evaluated in the argument list.

This feature is useful when we want to compute an expression and use it multiple times:

f = @(x,a=sort(x))a(a>.5);

One use case is when we use an indexed assignment to modify part of an array and we want to use the array:

a=[1 2 3 4 ]
a(2)=5;

But the expression (a(2)=5) returns a(2) no the whole array or the expression (a([1 3])=4) returna a two elements array. We can use the argument list:

f=@(a=[1 2 3 4],b=a(2)=5)a;

Here result of the indexed assignment is stored into a dummy varable b and the function returns the array.

#Using argument list:

Octave is capable to get default arguments so expressions can be evaluated in the argument list.

This feature is useful when we want to compute an expression and use it multiple times:

f = @(x,a=sort(x))a(a>.5);

One use case is when we use an indexed assignment to modify part of an array and we want to use the array:

a=[1 2 3 4]
a(2)=5;

But the expression (a(2)=5) returns a(2), or the expression (a([1 3])=4) returns a two elements array. Neither returns the whole array. We can use the argument list:

f=@(a=[1 2 3 4],b=a(2)=5)a;

Here the result of the indexed assignment is stored into a dummy variable b and the function returns the array.

Source Link
rahnema1
  • 5.7k
  • 1
  • 15
  • 22

#Using argument list:

Octave is capable to get default arguments so expressions can be evaluated in the argument list.

This feature is useful when we want to compute an expression and use it multiple times:

f = @(x,a=sort(x))a(a>.5);

One use case is when we use an indexed assignment to modify part of an array and we want to use the array:

a=[1 2 3 4 ]
a(2)=5;

But the expression (a(2)=5) returns a(2) no the whole array or the expression (a([1 3])=4) returna a two elements array. We can use the argument list:

f=@(a=[1 2 3 4],b=a(2)=5)a;

Here result of the indexed assignment is stored into a dummy varable b and the function returns the array.

AltStyle によって変換されたページ (->オリジナル) /