Expanding array by filling intermediate cells with mean of neighbour cells
3 views (last 30 days)
Show older comments
Hi,
I have 2 arrays and I want them to be nearly similar in length, however one array is of length 15 and the other is of length 30. So what I would like to do is double the length of the first array by putting in new cells in the array and put the mean of the neighbours in those cells.
For example: If we have the following array A.
A = [ 1 3 5 4 2]
Then I can create the following array B which is nearly double the size of A by just putting in the means of 2 neighbouring numbers in the cells between them.
B = [ 1 2 3 4 5 4.5 4 3 2]
Is there any function that does this automatically?
0 Comments
Answers (1)
Guillaume
on 19 Oct 2014
You may be able to do something with interp1, but even without the help of any function, it's fairly trivial:
tmp = [A(1:end-1); ((A(1:end-1) + A(2:end))/2];
B = [tmp(:)' A(end)]
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!