Create one vector from several iterations in for loop
Mostrar comentarios más antiguos
Hello, I am trying to split a vector into more pieces using a for loop. I have a vector, Lat, which contains latitude points. I wish to add more points in a linear fashion between the existing points in my Lat vector.
In order to do this, I am trying to use a for loop and the linspace operator as follows, splitting each interval in five new pieces.
for i = 1:length(Lat)-1
latitude(i) = linspace(Lat(i),Lat(i+1),5);
end
This does not work. How do I make the for loop understand that I wish to obtain a new vector containing all the points created using the linspace operator?
Respuesta aceptada
Más respuestas (1)
Andrei Bobrov
el 12 de Abr. de 2017
Editada: Andrei Bobrov
el 12 de Abr. de 2017
n = 5;
Latitude = [Lat(1);reshape(reshape(Lat(1:end-1),1,[])...
+ cumsum(ones(n,1)* diff(Lat(:)')/n),[],1)];
Categorías
Más información sobre Structures 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!