why this error occur ??Index exceeds matrix dimensions.

1 visualización (últimos 30 días)
Mohamed Eshag
Mohamed Eshag el 12 de Dic. de 2017
Editada: Stephen23 el 12 de Dic. de 2017
i want to convert one vector(u) to two vector (u1) and (u2);
n=401;
for i=1:n
u1(i)=u(i);
u2(i)=u(i+n);
end

Respuesta aceptada

KL
KL el 12 de Dic. de 2017
Editada: KL el 12 de Dic. de 2017
You can easily access those elements just by accessing thier corresponding indices but you should make sure you accessing elements that exist.
u = rand(1,801); %dummy data
n=401;
u(1:n)
u(n+1:end)
As you see, I've used end to access until the last element. It's equivalent to writing, u(n+1:numel(u)).
Do not create extra variables and it would only make your program prone to bugs.
  2 comentarios
Mohamed Eshag
Mohamed Eshag el 12 de Dic. de 2017
it is work now ,thanks and if I want to use for loop ,do you have any idea?
KL
KL el 12 de Dic. de 2017
Editada: KL el 12 de Dic. de 2017
if I want to use for loop ,do you have any idea?
What exactly are you trying to do? You probably won't even need a loop.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by