hi there
i need to do this if function
if a <= b
c = 1
else
c = realmin
but, a and b is a matrix (30x30)
and apparently i got only 1 value of c,
i want a the if function compare every cell of matrix a and b,
and gives me value in 30x30 matrix too
please help, thank you

 採用された回答

madhan ravi
madhan ravi 2018 年 11 月 12 日

0 投票

idx=a<b
c(idx)=1
c(~idx)=realmin

8 件のコメント

Antoni Ho
Antoni Ho 2018 年 11 月 12 日
it is actually works, but what is this idx actually? can i use it again on different variables?
madhan ravi
madhan ravi 2018 年 11 月 12 日
編集済み: madhan ravi 2018 年 11 月 12 日
use it is a logical index which stores the index of the variables when the condition is satisfied , yes you can use it on different variables also changing the variable name in the condition. see logical indexing for further explanation
Antoni Ho
Antoni Ho 2018 年 11 月 12 日
編集済み: madhan ravi 2018 年 11 月 12 日
thank you for your help
so the code is like this?
idx=a<b
c(idx)=1
c(~idx)=realmin
idx=d<e
f(idx)=1
f(~idx)=realmin
madhan ravi
madhan ravi 2018 年 11 月 12 日
編集済み: madhan ravi 2018 年 11 月 12 日
Anytime :),yes exactly , if it worked make sure to accept the answer
Antoni Ho
Antoni Ho 2018 年 11 月 12 日
編集済み: madhan ravi 2018 年 11 月 12 日
now i got this problem, i have (30x8 matrix). and the result i got from idx is 1 x 240 matrix. do you know how to make them 30 x 8 (i dont use normal matrix operation but elementwise only operation)
madhan ravi's reply : post a separate question by providing all the necessary details
Torsten
Torsten 2018 年 11 月 12 日
c = ones(size(a))
idx = a>=b
c(idx) = realmin
madhan ravi
madhan ravi 2018 年 11 月 12 日
+1 @Torsten - an absolut genius!!
Antoni Ho
Antoni Ho 2018 年 11 月 12 日
wow @Torsten real genius, it worked

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

その他の回答 (0 件)

カテゴリ

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

製品

リリース

R2018a

タグ

質問済み:

2018 年 11 月 12 日

コメント済み:

2018 年 11 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by