Hi there,
my question is how i need to change my matlab GUIDE code, so that the plots, that appear in my code, will also appear in the two "axes" areas in the GUIDE.
n = 3;
n1 = n-1;
a = 20; % Breite des Krummers entlang x
b = 10; % Höhe des Krümmers entlang y
P = [0 b;0 0;a 0]; % Punkte für Beziér-Spline Plot
T = 15; % Anazhl an Teilpunkten für den Plot
H = 8; % Höhe des Ausgangs
R = 2; % Radius des Eingangs
h = 6; % Breite des Ausgangs
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); %vpasolve löst Gleichungen mit Symbolvariablen
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';
% for i = 1:2
% pynew1 = r*(-1)^i;
% plot3(pxnew1,pynew1,pznew1,'r-o','MarkerSize',4)
% end
pynew1a = - r;
pynew1b = r;
%%%%%%%%%%Untere Linie
delta = - delta;
pxnew2 = px+newNormalToCurvex.*delta;
pznew2 = pz+newNormalToCurvez.*delta;
% for i = 1:2
% pynew1 = r*(-1)^i;
% plot3(pxnew2,pynew1,pznew2,'r-o','MarkerSize',4)
% end
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
%%%vorne links/rechts (magenta)
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;
% for i = 1:2
% pynew4 = ones(T,1).*e*(-1)^i;
% plot3(pxnew4,pynew4,pznew4,'m-o',"MarkerSize",4)
% end
pynew4a = -ones(T,1).*e;
pynew4b = ones(T,1).*e;
%%%%%vorne links/recht(grün)
pxnew5 = px-newNormalToCurvex.*j;
pznew5 = pz-newNormalToCurvez.*j;
% for i = 1:2
% pynew5 = ones(T,1).*e*(-1)^i;
% plot3(pxnew5,pynew5,pznew5,'g-o',"MarkerSize",4)
% end
pynew5a = pynew4a;
pynew5b = pynew4b;
%%%%%PLOT%%%%%%
plot3(px,py,pz,'b-o',"MarkerSize",4)
axis equal
axis tight
grid on
hold on
plot3(pxnew1,pynew1a,pznew1,'r-o','MarkerSize',4)
plot3(pxnew1,pynew1b,pznew1,'r-o','MarkerSize',4)
plot3(pxnew2,pynew2a,pznew2,'r-o','MarkerSize',4)
plot3(pxnew2,pynew2b,pznew2,'r-o','MarkerSize',4)
plot3(pxnew3a,pynew3a,pznew3a,'k-o','MarkerSize',4)
plot3(pxnew3b,pynew3a,pznew3b,'k-o','MarkerSize',4)
plot3(pxnew3a,pynew3b,pznew3a,'k-o','MarkerSize',4)
plot3(pxnew3b,pynew3b,pznew3b,'k-o','MarkerSize',4)
plot3(pxnew4,pynew4a,pznew4,'m-o',"MarkerSize",4)
plot3(pxnew4,pynew4b,pznew4,'m-o',"MarkerSize",4)
plot3(pxnew5,pynew5a,pznew5,'g-o',"MarkerSize",4)
plot3(pxnew5,pynew5b,pznew5,'g-o',"MarkerSize",4)
% view([0 0])
hold off
pxgesamt = [px;pxnew1; pxnew1; pxnew2; pxnew2; pxnew3a;pxnew3b;pxnew3a;pxnew3b;pxnew4; pxnew4; pxnew5; pxnew5];
pygesamt = [py;pynew1a;pynew1b;pynew2a;pynew2b;pynew3a;pynew3a;pynew3b;pynew3b;pynew4a;pynew4b;pynew5a;pynew5b];
pzgesamt = [pz;pznew1; pznew1; pznew2; pznew2; pznew3a;pznew3b;pznew3a;pznew3b;pznew4; pznew4; pznew5; pznew5];
pgesamt = [pxgesamt pygesamt pzgesamt];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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;
hold on
grid on
axis equal
axis tight
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;
p2z5 = -p2z4;
hold off
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(pyt,pzt,'o',"MarkerSize",3,"MarkerEdgeColor",'k')
hold on
end
axis equal
axis tight
grid on
for i = 1:T
pyt = [p2y1(i);p2y1b(i)];
pzt = [p2z1(i);p2z1(i)];
plot(pyt,pzt,'k-o',"MarkerSize",3,"MarkerEdgeColor",'k')
pyt = [p2y3(i); p2y3(i)];
pzt = [p2z3(i); p2z3b(i)];
plot(pyt,pzt,'k-o',"MarkerSize",3,"MarkerEdgeColor",'k')
pyt = [p2y2(i); p2y2b(i)];
pzt = [p2z2(i); p2z2(i)];
plot(pyt,pzt,'k-o',"MarkerSize",3,"MarkerEdgeColor",'k')
pyt = [p2y3b(i); p2y3b(i)];
pzt = [p2z3b(i); p2z3(i)];
plot(pyt,pzt,'k-o',"MarkerSize",3,"MarkerEdgeColor",'k')
hold on
end
axis equal
axis tight
grid on
%%%%%%%%%%%%%%%%%%%%%%%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(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(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(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(xc,yc,'Color','k')
hold on
end
hold off
I really don't know what i was doing with the changes of the code in the Guide, it was just me trying to do something.
I hope somebody can help me with it.
Thanks!

3 Kommentare

Tim Schaller
Tim Schaller am 7 Nov. 2022
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)
Image Analyst
Image Analyst am 7 Nov. 2022
Attach your .m file and .fig file with the paperclip icon. It will be then possible for people to download and run your program.
Tim Schaller
Tim Schaller am 8 Nov. 2022
Bearbeitet: Tim Schaller am 8 Nov. 2022
Good idea, thank you.
Is it working?
You can easily see my problem now. The 3D plot is working now, but the 2D plot just appears to do nothing.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Nipun
Nipun am 29 Dez. 2023

0 Stimmen

Hi Tim,
I understand that you are trying to plot the attached plots on a GUI built using GUIDE in MATLAB.
To display the plots within the axes areas of your MATLAB GUIDE GUI, you need to specify the axes handles when you call the plot3 or plot functions. These handles are usually created by GUIDE and can be accessed within the GUI's callback functions or anywhere in the GUI's code where you have access to the handles structure (usually named handles).
Here's a general way to use the axes handles:
% Example of plotting in the first axes area
axes(handles.axes1); % Set axes1 as the current axes
plot3(px, py, pz, 'b-o', 'MarkerSize', 4);
axis equal;
axis tight;
grid on;
% Example of plotting in the second axes area
axes(handles.axes2); % Set axes2 as the current axes
plot(pyt, pzt, 'o', 'MarkerSize', 3, 'MarkerEdgeColor', 'k');
axis equal;
axis tight;
grid on;
In your case, you should replace all occurrences of plot3 and plot with their axes-specific versions. Here's how you can modify some of your plotting code accordingly:
% Assuming you have two axes areas named axes1 and axes2 in GUIDE
% You would plot on axes1 like this:
axes(handles.axes1); % Set axes1 as the current axes
hold on;
plot3(px, py, pz, 'b-o', 'MarkerSize', 4);
plot3(pxnew1, pynew1a, pznew1, 'r-o', 'MarkerSize', 4);
plot3(pxnew1, pynew1b, pznew1, 'r-o', 'MarkerSize', 4);
% ... continue with other plot3 calls that should be in axes1 ...
hold off;
axis equal;
axis tight;
grid on;
% And on axes2 like this:
axes(handles.axes2); % Set axes2 as the current axes
hold on;
plot(pyt, pzt, 'o', 'MarkerSize', 3, 'MarkerEdgeColor', 'k');
% ... continue with other plot calls that should be in axes2 ...
hold off;
axis equal;
axis tight;
grid on;
Remember to replace handles.axes1 and handles.axes2 with the actual names of the axes handles in your GUIDE GUI. These names are defined when you create the axes objects in GUIDE and can be found in the tag property of each axes (e.g., 'tag' might be 'axes1' for the first axes).
If you are not sure about the names of your axes handles, you can check them in the .fig file using GUIDE, or by looking at the handles structure in the OpeningFcn of your GUI's .m file.
Finally, ensure that you have enabled the hold on and hold off commands appropriately for each axes so that multiple plots can be overlaid on the same axes without clearing the previous plots.
Hope this helps.
Regards,
Nipun

Kategorien

Mehr zu Graphics Object Properties finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 7 Nov. 2022

Beantwortet:

am 29 Dez. 2023

Community Treasure Hunt

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

Start Hunting!

Translated by