how can i vectorize this loop?
Mostrar comentarios más antiguos
% x is a vector given in main program
function y = userfunction2(x,k)
x=y;
for i=i:k
y=userfunction(y);
end
5 comentarios
Akira Agata
el 12 de Nov. de 2017
I don't think this function works.
What is the purpose of the second line ('x=y;')? Why input variable x is replaced by y? What is y??
What is the userfunction(y) in the third line?
William Brannon
el 12 de Nov. de 2017
Editada: Walter Roberson
el 12 de Nov. de 2017
William Brannon
el 12 de Nov. de 2017
William Brannon
el 12 de Nov. de 2017
William Brannon
el 12 de Nov. de 2017
Respuesta aceptada
Más respuestas (1)
Akira Agata
el 13 de Nov. de 2017
Seems that you would like to do circshift ?
Your 'y = ShiftLeft(x)' seems equivalent to 'y = circshift(x,1)', like:
x = 1:10;
y = circshift(x,1);
Then, y becomes
>> y
ans =
10 1 2 3 4 5 6 7 8 9
If you want to shift k times, you should simply do 'y = circshift(x,k)'. Please see more detail on circshift documentation page .
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!