我正在尝试在 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