Adding new values in between existing values in an array
Afficher commentaires plus anciens
I have 5 arrays with four values in each of them. Longitude array, Latitude Array, Velocity U array, Velocity V array and a time array in datenum form. This is ocean current data, and I want to simulate a ship moving through four values in 10 second intervals. So its like adding 360 points new datenum values between each datenum in the time array. So since the time array will increase if I did that. I would have to do something similar to the other arrays, but keep them the same length as the time array. That way i will be able to plot them. Since the velocity will not be in ascending order, how can fill the points in between each value. SO basically i want to make new points that coincide with the actual points.
Below I kind of tried to type what I want my code to do.
tarray: 4x1 single
lon: 4x1 double
lat: 4x1 double
u: 4x1 double
v: 4x1 double
after adding 10 seconds in between datenums
tarray: 1440x1 single
lon: 1440x1
lat: 1440x1
u: 1440x1
v: 1440x1
I'm not sure how to do this and I have been looking into it. If someone could help me progress into my study that would be great!
2 commentaires
Jorge Mario Guerra González
le 19 Jan 2017
If the array contains 4 elements and you want to add 360 elements in between, the final size should be 1080 instead of 1440. Taking into consideration that you want to respect the limits.
A= [1...(360 things)....2...(360 things)...3..(360 things)...4] .....360*3=1080.
Sancheet Hoque
le 20 Jan 2017
Réponse acceptée
Plus de réponses (1)
Jorge Mario Guerra González
le 19 Jan 2017
Modifié(e) : Jorge Mario Guerra González
le 19 Jan 2017
use the linspace function to add the values inbetween the array, also use an auxiliary variable. Maybe try this code.
tarray=[1000 2000 3000 4000];
spacing=360;
a=linspace(tarray(1),tarray(2),spacing);
new_tarray=linspace(tarray(1),tarray(2),spacing);
for i=2:length(tarray)-1
g=linspace(tarray(i),tarray(i+1),spacing+1);
new_tarray=[new_tarray g(2:end)];
end
tarray=new_tarray;
I know it's a bit rustic but does what I think you want. Also you can do the same fot the other arrays
Catégories
En savoir plus sur Time Series Objects dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
