Finding points inbetween the values of my arrays.

6 次查看(过去 30 天)
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.

采纳的回答

Daniel Pollard
Daniel Pollard 2021-1-5
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 个评论
Daniel Pollard
Daniel Pollard 2021-1-6
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by