Expanding array by filling intermediate cells with mean of neighbour cells

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

回答(1 个)

Guillaume
Guillaume 2014-10-19
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)]
  1 个评论
Mathieu
Mathieu 2014-10-19
编辑:Mathieu 2014-10-19
Is it possible that the second line contains an error? I can't seem to get the tmp(:)' to run.
Nvm, forgot a space.

请先登录,再进行评论。

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by