[英]IDL two step graph
我正在努力設置隨 x 范圍變化的 ay(x) 條件。 作為下面的例子,代碼想要 plot y=x 在 x=0 和 x=5.1 之間; 否則 y=2x。
編譯后,代碼會輸出以下內容: 在此上下文中,表達式必須是標量或 1 元素數組:
換句話說,不知道如何將數組變量“x”分配給 if 語句。
提前感謝大家的幫助。
PRO test
x = findgen(101.0,start=0)/10.0 ; 0.0 start, 10.0 end increment of 0.1
print,x
if x lt 5.1 then begin
y = 1.0 * x ;
endif else begin
y = 2.0* x
endelse
graph1=plot(x,y,thick=2,NAME=first,/CURRENT, $
linestyle = 0, ytitle=' y',xtitle='x' ) ; O
END
問題是您的IF
語句中的測試。 使用WHERE
代替執行以下操作。
y = x ;; need to initialize variable
low = WHERE(x lt 5.1,lw,COMPLEMENT=upp,NCOMPLEMENT=up)
IF (lw[0] GT 0) THEN y[low] = x[low] ;; technically don't need this line
IF (up[0] GT 0) THEN y[upp] = 2e0*x[upp]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.