# for文を使ったプロット

조회 수: 7(최근 30일)
Daichi 2022년 11월 21일
댓글: Atsushi Ueno 2022년 11월 22일

g = 9.81 ;
l=1;
L=1;
m0=1;
m1=1;
m2=1;
m3=1;
K= 30;
X=1:1:10;
for i=1:length(X)
F0x = zeros(1,length(X));
B = zeros(12,length(X));
A = zeros(12,13,length(X))
A1 = zeros(13,12,length(X))
A(:,:,i) = [1,0,0,0,0,0,-1,0,0,0,0,0,0;
0,1,0,0,0,0,0,-1,0,0,0,0,0;
0,0,0,0,0,0,-l*sin(X(i)),l*cos(X(i)),0,0,0,0,1;
0,0,1,0,0,0,0,0,-1,0,0,0,0;
0,0,0,1,0,0,0,0,0,-1,0,0,0;
0,0,0,0,0,0,0,0,-l*sin(X(i)),l*cos(X(i)),0,0,0;
0,0,0,0,1,0,0,0,0,0,-1,0,0;
0,0,0,0,0,1,0,0,0,0,0,-1,0;
0,0,0,0,0,0,0,0,0,0,-(l)*sin(X(i)),(l)*cos(X(i)),0;
0,0,0,0,0,0,1,0,1,0,1,0,0;
0,0,0,0,0,0,0,1,0,1,0,1,0;
0,0,0,0,0,0,0,L,0,0,0,-L,0];
A1(:,:,i) = pinv(A(:,:,i));
B(:,i) = [m0*sin(X(i));m0*(cos(X(i))+g);0;sin(X(i));cos(X(i))+g;0;sin(X(i));cos(X(i))+g;0;sin(X(i));cos(X(i))+g;0];
A2(:,:,i) = A1(:,:,i) * B(:,i)
F0x(1,i) = A2(1,1,i);
end
plot(X(i),F0x(i),"LineWidth",1.0)

댓글을 달려면 로그인하십시오.

### 채택된 답변

Atsushi Ueno 2022년 11월 21일
편집: Atsushi Ueno 2022년 11월 22일
>どうしたら正しくプロットできるか教えていただきたいです
for ループを10回回って抜け出た後の i の値は10です。
なので下記の plot 関数を実行するとx(10)に対するF0x(10)の1点しか表示されません。しかも plot 関数はデフォルトでマーカー(〇や＊等の印)を表示しない為、下記を実行しても何も表示されません。
plot(X(i),F0x(i),"LineWidth",1.0)

plot(X,F0x,"LineWidth",1.0);
plot(X(:),F0x(:),"LineWidth",1.0); % 上と同じ動作になる
plot(X(1:10),F0x(1:10),"LineWidth",1.0); % 上と同じ動作になる
##### 댓글 수: 2표시숨기기 이전 댓글 수: 1
Atsushi Ueno 2022년 11월 22일

F0x = zeros(1,length(X));
B = zeros(12,length(X));
A = zeros(12,13,length(X));
A1 = zeros(13,12,length(X));

댓글을 달려면 로그인하십시오.

### 범주

Find more on 対話型コントロールとコールバック in Help Center and File Exchange

R2022b

### Community Treasure Hunt

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

Start Hunting!