Finding points inbetween the values of my arrays.

I have five arrays each containing data for information at five year intervals (2000,2005,2010,2015,2020) i need to use this data to create data for all the years inbetween while maintaining the structure of the array. The array is a 4320x8640 single. I would prefer to take all points into account so the function would not be made of many straight lines, however if there is no way to do that it would be acceptable.

 Accepted Answer

If I understand your question, you want the interp1 command. You can choose how many target points to create, so make the lines as smooth as you want.
However, that will perform over 37 million interpolations. That's a lot, so will take a long time, but hopefully you realised that when you asked the question.

5 Comments

Do you have any idea how i would do this for multiple arrays without doing it in a loop. Im not quite sure how to use interp1 when considering multiple arrays rather than vectors as interp1 does not take in a cell array as an input im not sure how i could use all my arrays within the function? And yes i am aware it will take a while
Sorry, no, I would have used for loops to do this problem. Perhaps someone more experienced can see this and offer more advice, or know of a function better suited to what you want.
Could you possibly show me how to use for loops for this? I'm pretty new to MATLAB and am struggling with more complex loops.
My first thought would be to use a nested loop. So you have five arrays, let's call them A00, A05, A10, A15, A20. Each array has the size 4320x8640. So we could set up a loop which looks like
for ii = 1:4320
for jj = 1:8640
data_vec = [A00[ii, jj], A05[ii, jj], A10[ii, jj], A15[ii, jj], A20[ii, jj]];
interp_data = interp1(data_vec, linspace(0, 20, 21));
% Then some line which saves interp_data to an array,
% which you have preallocated.
end
end
I haven't tested this, so it might not work straight out of the box, but it certainly should get you going in the right direction. I'll reiterate though, that this code will be extremely slow. If you have the parallel computing toolbox, maybe you could use a parfor loop to speed things up a bit.
I'm sure there's a more efficient way to write this code. Hopefully this helps. Remember to look at the documentation if you get stuck, it really is great for Matlab.

Sign in to comment.

More Answers (0)

Products

Release

R2020b

Community Treasure Hunt

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

Start Hunting!