Slider in A graph
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi!
I'm trying to get A slider into A graph that can change a value and se how the graph changes. I'm new to Matlab and have no experience in programing. I have search the web and have found A fue ways to do it. But my function is very long and the value I want to change is not direcly in the funktion I plot. like this:
x=2
y=4-x
f=y+5
I want to change x with the slider. The ways I have found there is A callback, where the function you want to plot is put in and the value you vant to change is changed to "es.value". But that dose not work for me as my function is built on other functions.
My goal is to get 8 sliders into the graph that is for different variables and then be able to see what they do to the graph.
If someone can explain how to do it or even better show, I would really appreciate it. It is for A school project.
L1, L2, L3, L5, L6, L7, L8 and L12 is the variables I want to be able to change with A slider each. FCK is the function I plot. The text is in Swedish, and is referd to a drawing. "koncept8" is A refrens graph that is imported, not relevant for the problem.
L1=1.125; %%Från kordinaten 0 till EE
L2=0.9; %%Från kordinaten CC till EE
L3=1.35; %%Från kordinaten CC till DD
L5=0.225; %%DD:s x-kordinat
L6=0.45; %%DD:s y-kordinat
L7=-5.5; %%FF:s x-kordinat
L8=-0.45; %%FF:s y-kordinat
L11=2.7; %%Från kordinaten 0 till AA
L12=1.8; %%Från kordinaten BB till DD
FG=50000.*9.81; %%Kraften från vikten som lyfts
L4=sqrt((L5.^2)+(L6.^2)); %%Från kordinaten 0 till DD
V0=atand(L6./L5); %%Vinkel mellan armarnas infästning [Grader] (Alpha 0)
VT=-120:1:15; %%Totala vinkel mellan x-axeln och lyftarmen [Grader]
V1=VT-V0; %%Vinkeln till lyftarmen enligt beräkningsfigur [Grader] (Alpha 1)
VF=VT.*(-1); %%Vinkeln (Beta) för lyftarmen [Grader], (VT omgjord till minus)
K1=L4./L1; %%Anväds i beräkningarna tagna från rapport till literatirstudien
K2=L4./L2; %%Anväds i beräkningarna tagna från rapport till literatirstudien
K3=((L3.^2)-(L4.^2)-(L1.^2)-(L2.^2))./(2.*L1.*L2); %%Anväds i beräkningarna tagna från rapport till literatirstudien
A=cosd(V1)-K1+K2.*cosd(V1)+K3; %%Anväds i beräkningarna tagna från rapport till literatirstudien
B=-2.*sind(V1); %%Anväds i beräkningarna tagna från rapport till literatirstudien
C=K1+(K2-1).*cosd(V1)+K3; %%Anväds i beräkningarna tagna från rapport till literatirstudien
V2=2.*atand(((-B)-(sqrt((B.^2)-(4.*A.*C))))./(2.*A)); %%Vinkeln mellan L2 och L4 [Grader] (Alpha 2)
Cx=L1.*cosd(V1+V0)+(L2.*cosd(V2+V0)); %%CC:s x-kordinat
Cy=L1.*sind(V1+V0)+(L2.*sind(V2+V0)); %%CC:s y-kordinat
L3x=Cx-L5; %%Cx kordinat iförhållande till Dx
L3y=Cy-L6; %%Cy kordinat iförhållande till Dy
Dx=L5; %%DD:s x-kordinat
Dy=L6; %%DD:s y-kordinat
L12x=(L3x./L3).*L12; %%Bx kordinat iförhållande till Dx
L12y=(L3y./L3).*L12; %%By kordinat iförhållande till Dy
Bx=L12x+Dx; %%L3x.*((L12./L3)+Dx);
By=L12y+Dy; %%L3y.*((L12./L3)+Dy);
L9=(-1).*(L7)+Bx; %%Avståndet mellan kordinaterna Bx och Fx
L10=(-1).*(By-L8); %%Avståndet mellan kordinaterna By och Fy
V4=atand(L10./L9);
Ax=L11.*cosd(V1+V0); %%AA:s x-kordinat
Ay=L11.*sind(V1+V0); %%AA:s y-kordinat
Ex=L1.*cosd(V1+V0); %%EE:s x-kordinat
Ey=L1.*sind(V1+V0); %%EE:s y-kordinat
Rx=Dx-Cx; %%Avståndet mellan kordinaterna Dx och Cx
Ry=Dy-Cy; %%Avståndet mellan kordinaterna Dy och Cy
Vx=Dx-Bx; %%Avståndet mellan kordinaterna Dx och Bx
Vy=Dy-By; %%Avståndet mellan kordinaterna Dy och By
Jx=Ex-Cx; %%Avståndet mellan kordinaterna Cx och Ex
Jy=(-1).*(Cy-Ey); %%Avståndet mellan kordinaterna Cy och Ey
V3=atand(Jy./Jx); %%Vinkeln mellan x-axeln och "länken"
ML=Ax.*FG; %%Momentet från vikten som lyfts
FL=(ML)./((cosd(V3).*(-1).*(Ey))+(sind(V3).*Ex)); %%Kraften i länken mellan lyftarmen och dragarmen
FC=(FL.*((cosd(V3).*Ry)-(sind(V3).*Rx)))./((cosd(V4).*Vy)+(sind(V4).*Vx)); %%Cylinderkraften i Newton
FCK=FC.*0.001; %%Cylinderkraften i kiloNewton
%%x8=Koncept8(:,1); %%Koncept 8 komfortled
%%y8=Koncept8(:,2); %%Koncept 8 komfortled
G1=plot(VF,FCK);
hold on
%%G2=plot(x8,y8);
hold off
legend('Beräkning','Inventor','Location','northeast');
hold off
set([G1 G2],'LineWidth',2,'linestyle','-')
ylabel('Kraft [kN]')
xlabel('Vinkel [grader]')
title('Cylinderkraften beroende på vinkeln beta')
grid on
0 Kommentare
Antworten (0)
Siehe auch
Kategorien
Mehr zu Construction finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!