2016-12-19 6 views
0

xclick의 Scilab 설명서에서 출력 인수 cbmenu에 대한 설명을 이해할 수 없습니다.Scilab : xclick()에서 cbmenu를 사용하는 방법

은 말한다 :

cbmenu : 문자열 : xclick 반환하는 경우 인해 메뉴에서 클릭에 메뉴에 관련된 콜백.

웹에서 예제를 찾을 수 없으므로 여기에서 질문합니다. 나는 cbmenu와 관련이있는 요소들을 함께 뭉친 조각 (snippet)을 코딩했다. 스 니펫은 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를 사용하지 않지만 작동시키지 않아도됩니다. 코드를 실행하려면 먼저 "범위 선택"메뉴를 클릭 한 다음 그래프에서 두 번 클릭하십시오. 그런 다음 "Regression"메뉴가 활성화되고 "Linear regession"을 선택할 수 있습니다. "프로그램 종료"를 클릭하면 실행이 중단됩니다. 모든 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의 5 출력 인수()가 무엇을 할 수 있는지 설명하는 최소한의 스크립트는 다음과 같습니다

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

잘 했어 @ 로스 스톡! 나는 단지 원래의 질문을 약간 잘못 해석했다. :) – Attila