take the average of each column element of two rows (in a 2 dimensional array) and insert that average between the two rows
Show older comments
I'm trying to take the average of 2 row elements in a 2 dimensional array and insert that average between the two.
For example,with the array:
2,3,4
4,5,6
should result in:
2,3,4
3,4,5
4,5,6
3 Comments
Wayne King
on 24 Jul 2014
you don't say what you want to happen next, so do you want the average of rows 1 and 2, then 3 and 4, then 5 and 6...
Or do you want the average of rows 1 and 2, 2 and 3, 3 and 4...
Allan N
on 25 Jul 2014
Allan N
on 25 Jul 2014
Answers (3)
Andrei Bobrov
on 24 Jul 2014
out = sort([mean(x);x])
1 Comment
Image Analyst
on 25 Jul 2014
Works for that one case but won't work in general. Try it for this matrix:
m=[12,13,44;...
4,5,6]
dpb
on 24 Jul 2014
Edited: Andrei Bobrov
on 24 Jul 2014
The specific answer could be
x=[x(1,:);mean(x);x(2,:)];
As Wayne points out, you've not provided sufficient info to know precisely how to generalize to a more generic solution.
Image Analyst
on 25 Jul 2014
If you have the Image Processing Toolbox, you can simply use resize():
m=[2,3,4;...
4,5,6]
[rows, columns] = size(m); % Find out the size of m first.
% Insert mean rows.
out = imresize(m, [2*rows - 1, columns], 'bilinear')
Categories
Find more on Logical 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!