How to merge slider and graph to form a GUI

조회 수: 3 (최근 30일)
Sam
Sam 2013년 4월 18일
Hi,
I have two files. One plots 5 graphs as functions of e.
One of the graphs has a variable b, which I fixed as 2.
Now, I want to create a GUI so that I can vary b from 1.6 to 2.4.
The code for creating the GUI slider is in another file.
How do I 'merge' the two files into one document so that I can watch how my function changes when I slide the b value from 1.6 to 2.2? The code for plotting the graphs is:
% Plot for lambda.
n = 30;
EUD1 = [66/30;57/30;40/30;35/30;20/30]; EUD2 = [62/30;55/30;30/30;20/30;27/30];
conv_EUD = CC(EUD1, EUD2, 0.5);
dc1 = conv_EUD(1,1); dc2 = conv_EUD(2,1);
dn1 = conv_EUD(3,1); dn2 = conv_EUD(4,1); dn3 = conv_EUD(5,1);
e = -0.4:0.01:0.3;
bc1 = 30*dc1*(1+(dc1./(10+e))); bc2 = 30*dc2*(1+(dc2./(10+e)));
bn1 = 30*dn1*(1+(dn1./(2.2+e))); bn2 = 30*dn2*(1+(dn2./(2+e)));
b = 2;
bn3 = 30*dn3*(1+(dn3./(b+e)));
% Dn3 = (1/2)*((sqrt((2+e).^2+4*(2+e)*(40/30))) -(2+e)) % % Dn3 = (1/2)*(sqrt(((2+e).^2)+4*(2+e)*(40/30)) - (2+e)); % % bn3 = 30.*Dn3.*(1+(Dn3./(2+e))); % % % plot(e, Dn3, 'b');
% % hold on % plot(e,bn3,'g') % % title('plot'); % xlabel('Variation of Epsilon Signifying Change in alpha/beta Value'); % ylabel('d (Gy)'); % % % plot(e, bc1, 'g') hold all plot(e, bc2, 'r') hold all plot(e, bn1, 'b') hold all plot(e, bn2, 'y') hold all plot(e, bn3, 'c')
axescenter;
hleg1 = legend('BOOST','PTV', 'Spinal Cord', 'Parotid', 'Optics');
% hleg1 = legend('Optics'),
set(hleg1,'Location','South')
set(hleg1,'Interpreter','none')
set(gca,'XTick',-0.3:0.1:0.3)
set(gca,'XTickLabel',{'-0.3','-0.2','-0.1','0','0.1', '0.2', '0.3'})
ylim([-100 100]);
xlim([-0.3 0.3]);
title('BED Plots');
xlabel('Variation of Epsilon Signifying Change in alpha/beta Value');
ylabel('BED (Gy)');
The code for the slider is:
function gui(arg)
figure('MenuBar','none','Name','e','NumberTitle','off','Position',[200,200,260,60]);
Edit = uicontrol('Style','Edit','String','2.0','Position',[20,20,100,20],...
'CallBack', @EditCallBack, 'HorizontalAlignment','left');
Slider = uicontrol('Style','Slider','Position',[140,20,100,20],...
'CallBack', @SliderCallBack, 'Value',2.0,...
'Min',1.6,'Max',2.4);
function EditCallBack(varargin)
num = str2num(get(Edit,'String'));
if length(num) == 1 & num <=100 & num >=0
set(Slider,'Value',num);
else
msgbox('The value should be a number in the range [1.6,2.4]','Error','error','modal');
end
end;
function SliderCallBack(varargin)
num = get(Slider, 'Value');
set(Edit, 'String', num2str(num));
end;
end
The CC.m file is:
% Calculate the convex combination of two vecotrs
function conv_EUD=CC(EUD1,EUD2,lam) conv_EUD=lam*EUD1+(1-lam)*EUD2;
Thanks!

답변 (0개)

카테고리

Help CenterFile Exchange에서 Printing and Saving에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by