2016-12-19 31 views
0

我不明白xclick的Scilab文檔中輸出參數cbmenu的解釋。Scilab:如何在xclick中使用cbmenu()

它說:

CBMENU:字符串:關聯到一個菜單,如果xclick返回由於菜單上點擊回調。

我沒有在網上找到任何例子,所以我在這裏問。我已經編寫了一個片段,將可能與cbmenu相關的元素混爲一談。當我點擊CLICK時,該片段什麼也不做。任何人都可以修改/補充/修改代碼,以便它可以執行某些操作 - 無論是給我一個關於cbmenu可以做什麼的線索?

xdel() 
x=[-1 +1]; 
cf=figure(0); 
plot(x,x) 
m=uimenu(cf,'label','CLICK','callback','two=1+1'); 
[ibutton,xcoord,yxcoord,iwin,cbmenu]=xclick(); 

親切的問候

Rosestock

回答

0

如果我得到你的意圖吧,你想創建一個自定義菜單。這裏是一個小的演示,如何建立自定義菜單元素,以及如何使用locate獲取座標(但不需要xclick來感應菜單點擊)。這段代碼並沒有明確地使用cbmenu,但沒有必要讓它工作。如果您運行代碼,首先單擊「選擇範圍」菜單,然後在圖上單擊兩次。然後「迴歸」菜單被激活,您可以選擇「線性迴歸」。通過點擊「退出程序」,執行中止。並非所有nenu功能都已實施,它們僅用於演示多層結構。我希望它有幫助!

//Interactive menu demo 
// Scilab 5.5.2 
// 2016.12.20. Attila Eredics 
// 
//Attention! 
//Do not close the graphic window with the original x symbol 
// while the program is running, 
// because the program will run infinitely! 
// But you can stop it in the Consol with: Ctrl+C and then typing: abort 
clc; 
clear; 
lines(0); 

//artificial data vectors 
row = 100; 
t=gsort(rand(row,1),'r','i'); //time 
c=10*t+8;  //concentration 
c=c+rand(c); //add some noise 

//graphic window 
scf(0); clf(0); 
w=gcf(); //get current figure 

//new menu elements 
m3=uimenu(w,"Label","Select range","Callback","m=3"); 
m4=uimenu(w,"Label","Regression","Enable","off","ForegroundColor","0.5|0.5|0.5"); 
m41=uimenu(m4,"Label","Linear","Callback","m=41","Enable","on"); 
m42=uimenu(m4,"Label","Nonlinear","Callback","m=42","Enable","on"); 
m5=uimenu(w,"Label","Save results","Callback","m=5"); 
m6=uimenu(w,"Label","Exit program","Callback","abort","ForegroundColor","1|0|0"); 

plot2d(t,c,style=-5,frameflag=6); //plot the data 
xtitle("","time","concentration"); //axis labels 

while %T //infinite loop 
    //-------------wait for user action (click on a menu)------- 
    m=0; 
    while m<1 
     xpause(1e4); //pause 10ms 
    end 

    //------------------the menu actions------------------------- 
    if m==3 then //Select range 
     mprintf("\nChoose 2 points (click on the graph)!"); 
     coord=locate(2); //locate two clicks 
     disp(coord);  //coord: according to the axes 

     //Select range in t vector 
     for i=1:row-1 
      if coord(1,1)>=t(i) & coord(1,1)<t(i+1) then //t(i) <= 1st click < t(i+1) 
       i1=i; 
      end 
      if coord(1,2)>=t(i) & coord(1,2)<t(i+1) then //t(i) <= 2nd click < t(i+1) 
       i2=i; 
      end 
     end 

     //selected range 
     clear tt; 
     clear cc; 
     tt=t(i1:i2); 
     cc=c(i1:i2); 

     plot2d(tt,cc,style=-5); //plot selected points 
     h2=gce(); 
     h2.children.mark_foreground=3; //green 

     m4.Enable="on"; //enable Regression menu 
     m4.ForegroundColor="0|0|0" 
     m3.Enable="off"; //Disable selection menu 
     m3.ForegroundColor="0.5|0.5|0.5" 
    elseif m==41 then //linear regression of the selected points 
     mprintf("\nLinear regression"); 
     [a,b,sig]=reglin(tt',cc'); 

     plot2d([tt(1),tt($)],a*[tt(1),tt($)]+b,style=2); //blue line 

     m41.Enable="off"; //disable Linear regression menu 
     m41.ForegroundColor="0.5|0.5|0.5" 
    elseif m==42 then //Nonlinear regression 
     mprintf("\nNot implemented yet!"); 
    elseif m==5 then //Save 
     mprintf("\nNot implemented yet!"); 
    end 

end 
+0

我很熟悉的菜單和用他們幾次。我只關注'cbmenu'的功能。我能用它做什麼?唯一的信息是 - 正如我所引用的:cbmenu:String:如果xclick由於點擊菜單而返回,則與菜單關聯的回調。 – Rosestock

+0

我對菜單非常熟悉,並多次使用它們。我只關注'cbmenu'的功能。我能用它做什麼? ***唯一的信息是 - 正如我所引用的:'cbmenu:String:如果xclick由於點擊菜單返回而與菜單關聯的回調。' *** Sclab文檔經常會產生糟糕的英語。如果你理解這個短語,請通過重新編輯或編輯我的代碼片段來改進它,以使它具有某種功能***我的三顆星指示新的段落。返回鍵似乎做了別的。 – Rosestock

0

這是一個很小的腳本,它解釋了xclick第五屆輸出參數()可以這樣做:

xdel() 
x=[-1 +1]; 
winnum=1; win=string(winnum); 
cf=figure(winnum); 
plot(x,x) 
C=["Green" "Red" "Abort"];//case name strings 
addmenu(winnum, C(1)); C1="execstr("+C(1)+"_"+win+"(1))"; 
addmenu(winnum, C(2)); C2="execstr("+C(2)+"_"+win+"(1))"; 
addmenu(winnum, C(3)); C3="execstr("+C(3)+"_"+win+"(1))"; 
while %t 
    [!,!,!,!,cbmenu]=xclick(); 
    //Get the clicked option by cbmenu 
    if cbmenu==C1, cf.background=3; end 
    if cbmenu==C2, cf.background=5; end 
    if cbmenu==C3, break, end 
end 
+0

幹得好@Rosestock!我剛剛誤解了你的原始問題:) – Attila