Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

I want to store the matrices that are obtained from the loop each time.

조회 수: 1 (최근 30일)
Shourya Mukherjee
Shourya Mukherjee 2019년 3월 23일
마감: MATLAB Answer Bot 2021년 8월 20일
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

답변 (1개)

KALYAN ACHARJYA
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
  댓글 수: 2
Shourya Mukherjee
Shourya Mukherjee 2019년 3월 23일
Actually I am trying to enter qd as a 1X3 matrix having maximum velocities of 3 components in each row of the 3X3 q matrix (a particular row of q generalised by i), and in the step
t(i,j)=(q_next(i,j)-q_current(i,j))/qd(j)
I am trying to do an elementwise division such that
t(i,2)=(q_next(i,2)-q_current(i,2))/qd(1)
t(i,2)=(q_next(i,2)-q_current(i,2))/qd(2)
and so on
Shourya Mukherjee
Shourya Mukherjee 2019년 3월 23일
The main problem is that on different iterations of i, dimensions of tra are different (say 17X3 in first iteration, 8X3 in second and so on). So the tra(:,:,i) is not accepting different sized matrices. Any idea how to store different-sized matrices in a variable?

Community Treasure Hunt

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

Start Hunting!

Translated by