Info
此问题已关闭。 请重新打开它进行编辑或回答。
I want to store the matrices that are obtained from the loop each time.
1 次查看(过去 30 天)
显示 更早的评论
No matter how many times I try to store the matrices obtained at the end of the largest loop (i=1:m-1), it always ends up with a size mismatch error. Please Help!
q=input('Enter the q matrix:');
qd=input('Enter the maximum speed:');
m= size(q,1);
for i=1:m-1
q_current(i,:)=q(i,:);
q_next(i,:)=q(i+1,:);
for j=1:3
t(i,j)=(q_next(i,j)-q_current(i,j))/qd(j);
end
tmax(i)=max(t(i,:));
for j=1:3
qd_mod(i,j)=(q_next(i,j)-q_current(i,j))/tmax(i);
step_size(i,j)=0.001*qd_mod(i,j);
end
tra(:,:,i) = LinTra(q_current(i,:), q_next(i,:), step_size(i,:));
//This is where the mismatch problem arises. I want to store each matrix computed by LinTra() to the 3-dimensional matrix "tra". PLEASE HELP!!
end
The function LinTra is as follows:
function tra = LinTra(q_current, q_next, step_size)
q_step=q_current;
n=0;
while q_step<q_next
q_step=q_step+step_size;
n=n+1;
tra(n,:)=q_step;
end
for i=1:3
if tra(n,i)>q_next(i)
tra(n,i)=q_next(i);
end
end
end
0 个评论
回答(1 个)
KALYAN ACHARJYA
2019-3-23
编辑:KALYAN ACHARJYA
2019-3-23
q=input('Enter the q matrix:');
qd=input('Enter the maximum speed:');
m=size(q,1);
for i=1:m-1
q_current(i,:)=q(i,:);
q_next(i,:)=q(i+1,:);
for j=1:3
t(i,j)=(q_next(i,j)-q_current(i,j))/qd; % Here no qd(j), as qd defined as scalar
end
tmax(i)=max(t(i,:));
for j=1:3
qd_mod(i,j)=(q_next(i,j)-q_current(i,j))./tmax(i);
step_size(i,j)=0.001*qd_mod(i,j);
end
tra(:,:,i)=LinTra(q_current(i,:),q_next(i,:),step_size(i,:));
end
%Please note I didnot check the logic of the code
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!