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