Cody

Problem 44243. Ternary Conditional Operator

Created by LY Cao in Community

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

10.87% Correct | 89.13% Incorrect
Last solution submitted on Feb 20, 2019

Problem Comments

Recent Solvers4

Suggested Problems

More from this Author10

Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!