Returns one of two expressions depending on a condition.

(test) : (expression1) : (expression2)

test: Any Boolean expression.

expression1: A function handle called if test is true.

expression2: A function handle called if test is false.

Example

>> a = (2 > 1) : (@() 1) : (@() 2)
   a =
        1
>> a = (1 > 2) : (@() 1) : (@() 2)
   a =
        2

The colon.m you submitted will be moved to the class folder @function_handle:

mkdir @function_handle
movefile submission/colon.m @function_handle

Solution Stats

224 Solutions

13 Solvers

Last Solution submitted on May 29, 2026

Last 200 Solutions

Problem Comments

Solution Comments

Show comments
Loading...

Problem Recent Solvers13

Suggested Problems

More from this Author8

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!