フィルターのクリア

substitute if long statements by word or letter

2 ビュー (過去 30 日間)
Abdulaziz
Abdulaziz 2012 年 9 月 20 日
Hi guys;
please can any one tell me if I can substitute the long next if statement by one letter or word because I use it a lot in my code.
if ((sigma{1}(1))^2/((SL(1))^2))-(sigma{1}(1)*sigma{1}(2)/((SL(1))^2))+((sigma{1}(2))^2/((ST(1))^2))+((sigma{1}(3))^2/(SLT)^2)>=1....
||((sigma{2}(1))^2/((SL(2))^2))-(sigma{2}(1)*sigma{2}(2)/((SL(2))^2))+((sigma{2}(2))^2/((ST(2))^2))+((sigma{2}(3))^2/(SLT)^2)>=1....
||((sigma{3}(1))^2/((SL(3))^2))-(sigma{3}(1)*sigma{3}(2)/((SL(3))^2))+((sigma{3}(2))^2/((ST(3))^2))+((sigma{3}(3))^2/(SLT)^2)>=1....
||((sigma{4}(1))^2/((SL(4))^2))-(sigma{4}(1)*sigma{4}(2)/((SL(4))^2))+((sigma{4}(2))^2/((ST(4))^2))+((sigma{4}(3))^2/(SLT)^2)>=1
break;end

採用された回答

Walter Roberson
Walter Roberson 2012 年 9 月 20 日
Write a function (or function handle) and pass it sigma and SL and ST and SLT.
You can subdivide it into two parts, as the pattern of indices is regular
F1 = @(K,sigma,SL,ST,SLT) sigma{K}(1))^2/((SL(K))^2 <etc> >=1
F2 = @(sigma,SL,ST,SLT) F1(1,sigma,SL,ST,SLT) || F1(2,sigma,SL,ST,SLT) || F1(3,sigma,SL,ST,SLT) || F1(4,sigma,SL,ST,SLT)
  2 件のコメント
Abdulaziz
Abdulaziz 2012 年 9 月 21 日
I tried to but F2 in if statement but it was wrong the message is (Conversion to logical from function_handle is not possible.) should I put any thing with the F2 that contains all the conditions.
I appreciate your time and help
Walter Roberson
Walter Roberson 2012 年 9 月 21 日
You would use
if F2(sigma,SL,ST,SLT)

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

その他の回答 (1 件)

Abdulaziz
Abdulaziz 2012 年 9 月 21 日
Thank you very much Walter Roberson your answers always the best and must clear and specified.
I really appreciate your time.
Best, Aziz

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by