how to write a code for checkbox
이전 댓글 표시
Hi i have 3 plots in same figure,i want 3 checkboxes each plot and its corresponding axis shold be assigned to individal checkboxes. when i uncheck the checkbox plot and axis corresponding to that checkbox should be disappeared and again when i check the checkbox plot and axis of that checkeckbox should be displayed.here is my code,please help
x = 0:20;
N = numel(x);
y1 = rand(1,N);
y2 = 5.*rand(1,N)+5;
y3 = 50.*rand(1,N)-50;
%# Some initial computations:
axesPosition = [110 40 200 200]; %# Axes position, in pixels
yWidth = 30; %# y axes spacing, in pixels
xLimit = [min(x) max(x)]; %# Range of x values
xOffset = -yWidth*diff(xLimit)/axesPosition(3);
%# Create the figure and axes:
figure('Units','pixels','Position',[200 200 330 260]);
h1 = axes('Units','pixels','Position',axesPosition,...
'Color','w','XColor','k','YColor','r',...
'XLim',xLimit,'YLim',[0 1],'NextPlot','add');
h2 = axes('Units','pixels','Position',axesPosition+yWidth.*[-1 0 1 0],...
'Color','none','XColor','k','YColor','m',...
'XLim',xLimit+[xOffset 0],'YLim',[0 10],...
'XTick',[],'XTickLabel',[],'NextPlot','add');
h3 = axes('Units','pixels','Position',axesPosition+yWidth.*[-2 0 2 0],...
'Color','none','XColor','k','YColor','b',...
'XLim',xLimit+[2*xOffset 0],'YLim',[-50 50],...
'XTick',[],'XTickLabel',[],'NextPlot','add');
xlabel(h1,'time');
ylabel(h3,'values');
%# Plot the data:
plot1=plot(h1,x,y1,'r');
plot2=plot(h2,x,y2,'m');
plot3=plot(h3,x,y3,'b');
채택된 답변
추가 답변 (1개)
Image Analyst
2013년 2월 7일
0 개 추천
You're going to have to create checkboxes. Why not use GUIDE? Just place them on the window and right click and go to the callback and put in your code. Otherwise you'll have to do the same thing for checkboxes like you did with the axes and that's tedious.
Do you know that if you turn the axes off or make them invisible, that only affects the two axes (x & y) and the tick marks and labels? The background and stuff plotted or displayed in the axes will still be there - probably not what you want or were expecting. A work about is to put the axes in a panel and then you can turn the panel's visibility on or off and that will hide the entire axes and all its contents.
So, in the callback for the axes you can turn the panels on or off, or maybe you just want to call "cla reset" on the appropriate axes.
댓글 수: 2
rafi abdul
2013년 2월 8일
Image Analyst
2013년 2월 8일
In GUIDE, click on a control such as a checkbox or an axes in the panel of available controls. Click and drag it out to the size you want on the figure. See Doug Hull's videos for quick and easy basic training on GUIDE: http://blogs.mathworks.com/videos/category/gui-or-guide/
카테고리
도움말 센터 및 File Exchange에서 Graphics Object Properties에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!