gpt4 book ai didi

if-statement - idl elseif 问题/困惑

转载 作者:行者123 更新时间:2023-12-04 05:22:24 26 4
gpt4 key购买 nike

我试图在 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 [ 其他开始
声明
结束]

但是没有举例说明如何使用多个表达式和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

最佳答案

没有elseif IDL 中的声明。尝试:

a = 1
b = 0.5

diff = a - b
thres1 = 1
thres2 = -1

if (diff lt thres1 && diff gt thres2) then begin
print, 'case 1'
endif else if (diff gt thres1) then begin
print, 'case 2'
endif else if (diff lt thres2) then begin
print, 'case 3'
endif

关于if-statement - idl elseif 问题/困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13568557/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com