using max function without conditional function

how using max function, logical operators and comparison operators to write a code that if a number larger than 100, then return the difference between thwo values, and this number smaller than 100 then return 0.

6 件のコメント

KSSV
KSSV 2020 年 8 月 29 日
It is very simple what have you tried?
Maria
Maria 2020 年 8 月 29 日
I only know using 'if' conditional function
Rik
Rik 2020 年 8 月 29 日
That is enough. An else would make more sense, but you can use two if statements with opposite conditions. So let me repeat the question: what have you tried?
the cyclist
the cyclist 2020 年 8 月 29 日
@Maria: Part of the reason for asking to see what you have tried is that it helps understand how much MATLAB you know, see how close you are to solving the problem, and see how much effort you have put in yourself.
Without knowing those things, we don't know how much help you need, and we might waste a lot of your time and ours.
Maria
Maria 2020 年 8 月 29 日
if num>100
output= num-100
if num<=100
output=0
This is conditional function, but I cannot use conditional function to solve this. Only logical and comparsion or max function
dpb
dpb 2020 年 8 月 29 日
As this is obviously homework, it's not kosher to just provide the answer ... but hint: look at

サインインしてコメントする。

回答 (1 件)

Walter Roberson
Walter Roberson 2020 年 8 月 29 日

0 投票

A > B implies A - B > 0 . Which implies that the maximum of (A-B) and (0) is (A-B).
A < B implies A - B < 0. Which implies that the maximum of (A-B) and (0) is (0).

カテゴリ

ヘルプ センター および File ExchangeProgramming についてさらに検索

質問済み:

2020 年 8 月 29 日

回答済み:

2020 年 8 月 29 日

Community Treasure Hunt

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

Start Hunting!

Translated by