IDL に簡単な elseif ステートメントを入れようとしていますが、かなり苦労しています。matlab コードは次のようになります。
a = 1
b = 0.5
diff = a-b
thres1 = 1
thres2 = -1
if diff < thres1 & diff > thres2
'case 1'
elseif diff > thres1
'case 2'
elseif diff < thres2
'case 3'
end
しかし、IDL コードはそれほど単純ではなく、構文を正しく理解するのに苦労しています。ヘルプには次のように記載されています。 構文 IF 式 THEN ステートメント [ ELSE ステートメント ] または IF 式 THEN BEGIN ステートメント ENDIF [ ELSE BEGIN ステートメント ENDELSE ]
ただし、複数の式とelseifの使用方法の例は示していません。私は多くのバリエーションを試しましたが、うまくいかないようです。
誰にも提案がありますか?ここに私が試したいくつかのことがあります:
if (diff lt thres1) and (diff gt thres2) then begin
print, 'case 1'
endif else begin
if (diff gt thres1) then
print, 'case 2'
endif else begin
if (diff lt thres2) then
print, 'case 3'
endif
if (diff lt thres1) and (diff gt thres2) then begin
print, 'case 1'
else (diff gt thres1) then
print, 'case 2'
else (diff lt thres2) then
print, 'case 3'
endif