take the average of each column element of two rows (in a 2 dimensional array) and insert that average between the two rows
1 view (last 30 days)
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
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.
0 Comments
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')
0 Comments
See Also
Categories
Find more on Creating and Concatenating Matrices 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!