Why is my plot not showing?
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
a1 = 0; alpha1 = 0; d1 = 0;
a2 = 475; alpha2 = pi/2; d2 = 150;
a3 = 600; alpha3 = 0; d3 = 0;
%DH parameter
t1_min = -pi/2; t1_max = pi/2;
t2_min = -pi/3; t2_max = pi/3;
t3_min = -pi/3; t3_max = pi/3;
% joint limits
% Monte Carlo method
% sampling size
N = 20000;
t1 = t1_min + (t1_max-t1_min)*rand(N,1);
t2 = t2_min + (t2_max-t2_min)*rand(N,1);
t3 = t3_min + (t3_max-t3_min)*rand(N,1);
function [ T ] = TranMat( a,b,c,d )
T = [ cos(d) -sin(d)*cos(b)
sin(d)*sin(b) a*cos(d); sin(d)
cos(d)*cos(b) -cos(d)*sin(b) a*sin(d);
0 sin(b) cos(b) c;
0 0 0 1
];
for i = 1:N
A1 = TransMat(a1,alpha1,d1,t1(i));
A2 = TransMat(a2,alpha2,d2,t2(i));
A3 = TransMat(a3,alpha3,d3,t3(i));
T = A1*A2*A3;
X=T(1,4);
Y=T(2,4);
Z=T(3,4);
plot3(X,Y,Z,'.')
hold on;
end
end
채택된 답변
Geoff Hayes
2020년 6월 22일
0 개 추천
Tony - your code is not calling the TranMat function which has the code to plot the data. How should it be called? What do the a, b, c, and d input parameters correspond to in the script code?
댓글 수: 9
Thanks, it was a typo for "TransMat", and a, b,c,d are corresponded to a1,alpha1,d1,t1(i). I fixed the typo but the plot is still not showing. I don't see A1 to A3 show up in my workspace.
Geoff Hayes
2020년 6월 22일
But you are then calling TransMat from itself (is this intentional?)
function [ T ] = TransMat( a,b,c,d )
T = [ cos(d) -sin(d)*cos(b)
sin(d)*sin(b) a*cos(d); sin(d)
cos(d)*cos(b) -cos(d)*sin(b) a*sin(d);
0 sin(b) cos(b) c;
0 0 0 1
];
for i = 1:N
A1 = TransMat(a1,alpha1,d1,t1(i));
A2 = TransMat(a2,alpha2,d2,t2(i));
A3 = TransMat(a3,alpha3,d3,t3(i));
T = A1*A2*A3;
X=T(1,4);
Y=T(2,4);
Z=T(3,4);
plot3(X,Y,Z,'.')
hold on;
end
end
How should it be called from the remainder of the code?
Tony Yu
2020년 6월 22일
편집: Geoff Hayes
2020년 6월 22일
clc;
clear all;
syms a b c d
syms t1_min t2_min t3_min t4_min t5_min t6_min t7_min t1_max t2_max t3_max t4_max t5_max t6_max t7_max
a1 = 475; alpha1 = pi/2; d1 = 150;
a2 = 600; alpha2 = 0; d2 = 0;
a3 = 120; alpha3 = 0; d3 = 720;
%DH parameter
t1_min = -pi/2; t1_max = pi/2;
t2_min = -pi/3; t2_max = pi/3;
t3_min = -pi/3; t3_max = pi/3;
% joint limits
% Monte Carlo method
% sampling size
N = 20000;
t1 = t1_min + (t1_max-t1_min)*rand(N,1);
t2 = t2_min + (t2_max-t2_min)*rand(N,1);
t3 = t3_min + (t3_max-t3_min)*rand(N,1);
for i = 1:N
A1 = TransMat(a1,alpha1,d1,t1(i));
A2 = TransMat(a2,alpha2,d2,t2(i));
A3 = TransMat(a3,alpha3,d3,t3(i));
T = A1*A2*A3;
X=T(1,4);
Y=T(2,4);
Z=T(3,4);
plot3(X,Y,Z,'.')
hold on;
end
figure(1)
view(3);
title('Isometric view');
xlabel('x (m)');
ylabel('y (m)');
zlabel('z (m) ');
figure(2)
view(2); % top view
title(' Top view');
xlabel('x (m)');
ylabel('y (m)');
figure(3)
view([1 0 0]); % y-z plane
title('Side view, Y-Z');
ylabel('y (m)');
zlabel('z (m)');
function T = TransMat(a,b,c,d)
T = [cos(d) -sin(d)*cos(b) sin(d)*sin(b) a*cos(d); sin(d) cos(d)*cos(b) -cos(d)*sin(b) a*sin(d); 0 sin(b) cos(b) c; 0 0 0 1];
end
I have fixed the code and it is working now, but now, figure 2 and figure 3 does not show anything
Geoff Hayes
2020년 6월 22일
But what should figure 2 and figure 3 show? There is no code to plot something to those figures as your for loop would only be plotting to the first figure.
Tony Yu
2020년 6월 22일
Is there a way to plot my for loop for the second figure and third figure with view(2) and view ([1 0 0])?
Try not giving figure numbers as input, just accepting handles as outputs (if you even need to):
Instead of
figure(1)
figure(2)
do it like this:
h1 = figure;
h2 = figure;
etc.
Geoff Hayes
2020년 6월 22일
You could defer the plots until after the loop. Perhaps
N = 20000;
t1 = t1_min + (t1_max-t1_min)*rand(N,1);
t2 = t2_min + (t2_max-t2_min)*rand(N,1);
t3 = t3_min + (t3_max-t3_min)*rand(N,1);
X = zeros(N,1); % <--- presize X,Y,Z
Y = zeros(N,1);
Z = zeros(N,1);
for i = 1:N
A1 = TransMat(a1,alpha1,d1,t1(i));
A2 = TransMat(a2,alpha2,d2,t2(i));
A3 = TransMat(a3,alpha3,d3,t3(i));
T = A1*A2*A3;
X(i)=T(1,4);
Y(i)=T(2,4);
Z(i)=T(3,4);
end
figure(1)
view(3);
title('Isometric view');
xlabel('x (m)');
ylabel('y (m)');
zlabel('z (m) ');
plot3(X,Y,Z,'.'); % <---- plot for figure 1
figure(2)
view(2); % top view
title(' Top view');
xlabel('x (m)');
ylabel('y (m)');
plot3(X,Y,Z,'.') % <---- plot for figure 2
figure(3)
view([1 0 0]); % y-z plane
title('Side view, Y-Z');
ylabel('y (m)');
zlabel('z (m)');
plot3(X,Y,Z,'.') % <---- plot for figure 3
I haven't tested the above but it might work...
Tony Yu
2020년 6월 22일
I tried your meathod but all 3 figures are showing view(3)...
Tony Yu
2020년 6월 22일
It works now, seems like it does not need to call out plot3 again on figure 2 and 3, thanks !
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Line Plots에 대해 자세히 알아보기
태그
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
