Selecting a specific answer

3 ビュー (過去 30 日間)
Adam Francki
Adam Francki 2019 年 3 月 19 日
回答済み: Krishna Zanwar 2019 年 3 月 22 日
if i had four values. For example,
a=100
b=-100
c=30
d=100
and i wanted the variable ‘e’ to equal the value which has been repeated (100). how would a write a function that inspects the values of a,b,c and d, determines which two are the same and equates that to the output as e. (so in the exanple. answer is e=100)

回答 (1 件)

Krishna Zanwar
Krishna Zanwar 2019 年 3 月 22 日
You can use the function any to find out if any of the variables is equal to any other variable.
any(a==[b c d])
will gave a logical 1 if 'a' is matching with any of the other variables.
You can see how to write a function here.

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by