Ternary Conditional Operator - MATLAB Cody - MATLAB Central

Problem 44243. Ternary Conditional Operator

Difficulty:Rate

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

7.58% Correct | 92.42% Incorrect
Last Solution submitted on Nov 28, 2024

Problem Comments

Solution Comments

Show comments
PIVlab surpasses 100K all-time File Exchange downloads
During the past twelve months, PIVlab, a MATLAB Community Toolbox for particle...
3
5
LLMs with MATLAB updated to support the latest OpenAI Models
Large Languge model with MATLAB, a free add-on that lets you access...
2
4

Problem Recent Solvers12

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!
Go to top of page