Borrar filtros
Borrar filtros

Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

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

2 visualizaciones (últimos 30 días)
Shourya Mukherjee
Shourya Mukherjee el 23 de Mzo. de 2019
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
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

Respuestas (1)

KALYAN ACHARJYA
KALYAN ACHARJYA el 23 de Mzo. de 2019
Editada: KALYAN ACHARJYA el 23 de Mzo. de 2019
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 comentarios
Shourya Mukherjee
Shourya Mukherjee el 23 de Mzo. de 2019
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 el 23 de Mzo. de 2019
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?

La pregunta está cerrada.

Community Treasure Hunt

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

Start Hunting!

Translated by