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.
댓글 수: 0
채택된 답변
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
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 Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!