을 간주한다. 여기에 작은 데모, 사용자 정의 메뉴 요소를 부과하는 방법 및 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
나는 메뉴가 아주 잘 알고 그들에게 여러 번 사용했다. 내 초점은 'cbmenu'기능뿐입니다. 내가 그걸로 무엇을 할 수 있는지. 유일한 정보는 - 제가 인용 한 것처럼 : cbmenu : String : 메뉴 클릭으로 인해 xclick이 반환되면 메뉴에 연결된 콜백입니다. – Rosestock
저는 메뉴에 익숙하며 여러 번 사용했습니다. 내 초점은 'cbmenu'기능뿐입니다. 내가 그걸로 무엇을 할 수 있니? *** 유일한 정보는 - 인용 한 바와 같이 : 'cbmenu : String : 메뉴 클릭으로 인해 xclick이 반환되면 메뉴에 연결된 콜백입니다.' *** Sclab 설명서는 빈약 한 영어를 자주 만듭니다. 이 구문을 이해한다면, 코드 조각을 수정하거나 편집하여 코드 조각을 향상 시키십시오. *** 그 중 세 개의 별은 새로운 단락을 나타내는 것입니다. 리턴 키는 다른 일을하는 것처럼 보입니다. – Rosestock