So I changed the Code to the following, but somehow the second plot does not work.
If I try to include it, it just changes my first plot, but not give me a second one.
function varargout = BA(varargin)
% BA MATLAB code for BA.fig
% BA, by itself, creates a new BA or raises the existing
% singleton*.
%
% H = BA returns the handle to a new BA or the handle to
% the existing singleton*.
%
% BA('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in BA.M with the given input arguments.
%
% BA('Property','Value',...) creates a new BA or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before BA_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to BA_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help BA
% Last Modified by GUIDE v2.5 07-Nov-2022 15:03:53
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @BA_OpeningFcn, ...
'gui_OutputFcn', @BA_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before BA is made visible.
function BA_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to BA (see VARARGIN)
% Choose default command line output for BA
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes BA wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = BA_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
a = str2double(get(handles.a_input,'String'));
b = str2double(get(handles.b_input,'String'));
H = str2double(get(handles.H_input,'String'));
h = str2double(get(handles.h__input,'String'));
R = str2double(get(handles.R_input,'String'));
T = str2double(get(handles.T_input,'String'));
%%%%%%%%%%%%%%%%%%%%CODE%%%%%%%%%%%%%%%%%%
n = 3;
n1 = n-1;
P = [0 b;0 0;a 0];
syms t s(t)
B = bernsteinMatrix(n1,t);
bezierCurve = B*P;
s(t) = int(norm(diff(bezierCurve)),0,t);
snum = linspace(0,s(1),T);
for i = 1:T
tnum(i) = vpasolve(snum(i)==s(t),t);
end
px = double(subs(bezierCurve(:,1),t,tnum)).';
py = zeros(T,1);
pz = double(subs(bezierCurve(:,2),t,tnum)).';
normalToCurve = diff(bezierCurve)*[0 1;-1 0];
normalToCurve = normalToCurve/norm(normalToCurve);
newNormalToCurve = [double(subs(normalToCurve(1),t,tnum))' double(subs(normalToCurve(2),t,tnum))'];
newNormalToCurvex = newNormalToCurve(:,1);
newNormalToCurvez = newNormalToCurve(:,2);
%%%%%%%%%%%Obere Linie
for i = 1:T
S = double(s((i-1)/(T-1)));
d = R*(1-S/double(s(1)))+(H/2)*S/double(s(1));
delta(i) = d;
end
delta = delta';
pxnew1 = px+newNormalToCurvex.*delta;
pznew1 = pz+newNormalToCurvez.*delta;
for i = 1:T
S = double(s((i-1)/(T-1)));
rhilfe = (h/2)*S/double(s(1));
r(i) = rhilfe;
end
r = r';
pynew1a = - r;
pynew1b = r;
%%%%%%%%%%Untere Linie
delta = - delta;
pxnew2 = px+newNormalToCurvex.*delta;
pznew2 = pz+newNormalToCurvez.*delta;
pynew2a = pynew1a;
pynew2b = pynew1b;
%%%%%%%%%%seitliche Linien (schwarz)
for i = 1:T
S = double(s((i-1)/(T-1)));
chilfe = R*(1-S/double(s(1)))+(h/2)*S/double(s(1));
c(i) = chilfe;
end
for i = 1:T
S = double(s((i-1)/(T-1)));
lhilfe = H/2*S/double(s(1));
l(i) = lhilfe;
end
l = l';
c = c';
pynew3 = ones(T,1).*c;
pxnew3a = px-newNormalToCurvex.*l;
pxnew3b = px+newNormalToCurvex.*l;
pznew3a = pz-newNormalToCurvez.*l;
pznew3b = pz+newNormalToCurvez.*l;
pynew3a = pynew3;
pynew3b = -pynew3;
%%%%%%%%%%%%4Ecken
Rnewx = R*cos(pi/4);
Rnewy = R*cos(pi/4);
for i = 1:T
S = double(s((i-1)/(T-1)));
jhilfe = Rnewx*(1-S/double(s(1)))+(H/2)*S/double(s(1));
j(i) = jhilfe;
end
for i = 1:T
S = double(s((i-1)/(T-1)));
ehilfe = Rnewy*(1-S/double(s(1)))+(h/2)*S/double(s(1));
e(i) = ehilfe;
end
j = j';
e = e';
pxnew4 = px+newNormalToCurvex.*j;
pznew4 = pz+newNormalToCurvez.*j;
pynew4a = -ones(T,1).*e;
pynew4b = ones(T,1).*e;
pxnew5 = px-newNormalToCurvex.*j;
pznew5 = pz-newNormalToCurvez.*j;
pynew5a = pynew4a;
pynew5b = pynew4b;
%%%%%%%%%%%%%%%%%%CODE ENDE%%%%%%%%%%%%%%%%%%%
plot3(handles.axes1,px,py,pz,'b-',"MarkerSize",4)
axis equal
axis tight
grid on
hold on
plot3(handles.axes1,pxnew1,pynew1a,pznew1,'r-','MarkerSize',4)
plot3(handles.axes1,pxnew1,pynew1b,pznew1,'r-','MarkerSize',4)
plot3(handles.axes1,pxnew2,pynew2a,pznew2,'r-','MarkerSize',4)
plot3(handles.axes1,pxnew2,pynew2b,pznew2,'r-','MarkerSize',4)
plot3(handles.axes1,pxnew3a,pynew3a,pznew3a,'k-','MarkerSize',4)
plot3(handles.axes1,pxnew3b,pynew3a,pznew3b,'k-','MarkerSize',4)
plot3(handles.axes1,pxnew3a,pynew3b,pznew3a,'k-','MarkerSize',4)
plot3(handles.axes1,pxnew3b,pynew3b,pznew3b,'k-','MarkerSize',4)
plot3(handles.axes1,pxnew4,pynew4a,pznew4,'m-',"MarkerSize",4)
plot3(handles.axes1,pxnew4,pynew4b,pznew4,'m-',"MarkerSize",4)
plot3(handles.axes1,pxnew5,pynew5a,pznew5,'g-',"MarkerSize",4)
plot3(handles.axes1,pxnew5,pynew5b,pznew5,'g-',"MarkerSize",4)
hold off
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% arclen = arclength(px,pz);
% S = linspace(0,arclen,T);
%
% %obere Linien
% p2y1 = linspace(0,h/2,T);
% for i = 1:T
% z2t = R*(1-S(i)/arclen)+(H/2)*S(i)/arclen;
% z2(i) = z2t;
% end
% z2 = z2';
% p2z1 = z2;
% p2y1b = -p2y1;
%
% %untere Linien
% p2y2 = p2y1;
% p2z2 = -p2z1;
% p2y2b = p2y1b;
%
% %seitliche Linien
% for i = 1:T
% c2hilfe = R*(1-S(i)/arclen)+h/2*(S(i)/arclen);
% c2(i) = c2hilfe;
% end
% c2 = c2';
% p2y3 = c2;
% p2z3 = linspace(0,H/2,T);
% p2z3b = -p2z3;
% p2y3b = -p2y3;
%
% %oben vorne/hinten (magenta)
% Rnew = R*cos(pi/4);
% for i = 1:T
% j2hilfe = Rnew*(1-S(i)/arclen)+(H/2)*S(i)/arclen;
% j2(i) = j2hilfe;
% end
% for i = 1:T
% e2hilfe = Rnew*(1-S(i)/arclen)+(h/2)*S(i)/arclen;
% e2(i) = e2hilfe;
% end
% j2 = j2';
% e2 = e2';
% p2y4 = e2;
% p2z4 = j2;
% p2y4b = -p2y4;
%
% % unten vorne/hinten (grün)
% p2z5 = -p2z4;
%
% for i = 1:T
% pyt = [p2y1(i); p2y4(i); p2y3(i); p2y3(i); p2y4(i); p2y2(i); p2y2b(i); p2y4b(i);
% p2y3b(i); p2y3b(i); p2y4b(i); p2y1b(i); p2y1(i)];
% pzt = [p2z1(i); p2z4(i); p2z3(i); p2z3b(i); p2z5(i); p2z2(i); p2z2(i); p2z5(i);
% p2z3b(i); p2z3(i); p2z4(i); p2z1(i); p2z1(i)];
% plot(handles.axes2,pyt,pzt,'o',"MarkerSize",3,"MarkerEdgeColor",'k')
% hold on
% end
% axis equal
% axis tight
% grid on
% view([0 1])
% for i = 1:T
% pyt = [p2y1(i);p2y1b(i)];
% pzt = [p2z1(i);p2z1(i)];
% plot(handles.axes2,pyt,pzt,'k-o',"MarkerSize",3,"MarkerEdgeColor",'k')
% pyt = [p2y3(i); p2y3(i)];
% pzt = [p2z3(i); p2z3b(i)];
% plot(handles.axes2,pyt,pzt,'k-o',"MarkerSize",3,"MarkerEdgeColor",'k')
% pyt = [p2y2(i); p2y2b(i)];
% pzt = [p2z2(i); p2z2(i)];
% plot(handles.axes2,pyt,pzt,'k-o',"MarkerSize",3,"MarkerEdgeColor",'k')
% pyt = [p2y3b(i); p2y3b(i)];
% pzt = [p2z3b(i); p2z3(i)];
% plot(handles.axes2,pyt,pzt,'k-o',"MarkerSize",3,"MarkerEdgeColor",'k')
% hold on
% end
%
% %%%%%%%%%%%%%%%%%%%%%%%Ecken abrunden%%%%%%%%%%%%%%%%%%%%%
% %radius (Funktion für linear sinkenden Radius)
% for i = 1:T
% radius = R*(1-S(i)/arclen);
% rad(i) = radius;
% end
% rad = rad';
% % Mittelpunkt
% for i = 1:T
% MPxhilfe = h/2*S(i)/arclen;
% MPx(i) = MPxhilfe;
% MPyhilfe = H/2*S(i)/arclen;
% MPy(i) = MPyhilfe;
% end
% MPx = MPx';
% MPy = MPy';
% MP = [MPx MPy];
% % Winkel
% deg = 90:-1:0;
% for i = 1:T
% xc = MP(i,1)+rad(i)*cosd(deg);
% yc = MP(i,2)+rad(i)*sind(deg);
% plot(handles.axes2,xc,yc,'Color','k')
% hold on
% end
% axis tight
% axis equal
% grid on
% for i = 1:T
% xc = MP(i,1)+rad(i)*cosd(deg);
% yc = -MP(i,2)-rad(i)*sind(deg);
% plot(handles.axes2,xc,yc,'Color','k')
% hold on
% end
% for i = 1:T
% xc = -MP(i,1)-rad(i)*cosd(deg);
% yc = -MP(i,2)-rad(i)*sind(deg);
% plot(handles.axes2,xc,yc,'Color','k')
% hold on
% end
% for i = 1:T
% xc = -MP(i,1)-rad(i)*cosd(deg);
% yc = MP(i,2)+rad(i)*sind(deg);
% plot(handles.axes2,xc,yc,'Color','k')
% hold on
% end
% hold off
function a_input_Callback(hObject, eventdata, handles)
% hObject handle to a_input (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of a_input as text
% str2double(get(hObject,'String')) returns contents of a_input as a double
% --- Executes during object creation, after setting all properties.
a = str2double(get(hObject,'String'));
function a_input_CreateFcn(hObject, eventdata, handles)
% hObject handle to a_input (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function b_input_Callback(hObject, eventdata, handles)
% hObject handle to b_input (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of b_input as text
% str2double(get(hObject,'String')) returns contents of b_input as a double
% --- Executes during object creation, after setting all properties.
b = str2double(get(hObject,'String'));
function b_input_CreateFcn(hObject, eventdata, handles)
% hObject handle to b_input (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function H_input_Callback(hObject, eventdata, handles)
% hObject handle to H_input (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of H_input as text
% str2double(get(hObject,'String')) returns contents of H_input as a double
% --- Executes during object creation, after setting all properties.
H = str2double(get(hObject,'String'));
function H_input_CreateFcn(hObject, eventdata, handles)
% hObject handle to H_input (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function h__input_Callback(hObject, eventdata, handles)
% hObject handle to h__input (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of h__input as text
% str2double(get(hObject,'String')) returns contents of h__input as a double
% --- Executes during object creation, after setting all properties.
h = str2double(get(hObject,'String'));
function h__input_CreateFcn(hObject, eventdata, handles)
% hObject handle to h__input (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function R_input_Callback(hObject, eventdata, handles)
% hObject handle to R_input (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of R_input as text
% str2double(get(hObject,'String')) returns contents of R_input as a double
% --- Executes during object creation, after setting all properties.
R = str2double(get(hObject,'String'));
function R_input_CreateFcn(hObject, eventdata, handles)
% hObject handle to R_input (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function T_input_Callback(hObject, eventdata, handles)
% hObject handle to T_input (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of T_input as text
% str2double(get(hObject,'String')) returns contents of T_input as a double
% --- Executes during object creation, after setting all properties.
T = str2double(get(hObject,'String'));
function T_input_CreateFcn(hObject, eventdata, handles)
% hObject handle to T_input (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes during object creation, after setting all properties.
function axes1_CreateFcn(hObject, eventdata, handles)
% hObject handle to axes1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: place code in OpeningFcn to populate axes1
% --- Executes during object deletion, before destroying properties.
function axes1_DeleteFcn(hObject, eventdata, handles)
% hObject handle to axes1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on mouse press over axes background.
function axes1_ButtonDownFcn(hObject, eventdata, handles)
% hObject handle to axes1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes during object creation, after setting all properties.
function axes2_CreateFcn(hObject, eventdata, handles)
% hObject handle to axes2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: place code in OpeningFcn to populate axes2
% --- Executes during object deletion, before destroying properties.
function axes2_DeleteFcn(hObject, eventdata, handles)
% hObject handle to axes2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on mouse press over axes background.
function axes2_ButtonDownFcn(hObject, eventdata, handles)
% hObject handle to axes2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)