Info

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

For loop of array

1 visualización (últimos 30 días)
Yat Sheng Kong
Yat Sheng Kong el 11 de Jul. de 2017
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
Hi,
I have tried for loop to run a vector but having an error. Could anyone tell me how to loop the vector.
x = ones(10,1);
for k = 1:10
y(k) = x + k
end
Thanks, Kong
  1 comentario
Jan
Jan el 12 de Jul. de 2017
Whenever you mention in the forum, that you "have an error", post a copy of the complete message. Otherwise the readers cannot guess, what the problem is.

Respuestas (1)

KSSV
KSSV el 11 de Jul. de 2017
x = ones(10,1);
y=zeros(10,1);
for k = 1:10
y(k) = x(k) + k
end
The same thing can be achieved using:
y=x+1:10;
  2 comentarios
Yat Sheng Kong
Yat Sheng Kong el 12 de Jul. de 2017
Initially, x = [1,1,1,1,1,1,1,1,1,1] and I wish to have it to become like x = [2,2,2,2,2,2,2,2,2,2] and so on.
KSSV
KSSV el 12 de Jul. de 2017
x = ones(10,1);
y=zeros(10,1);
for k = 1:10
y(k) = x(k) + 1
end
Or
y=x+1 ;

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by