take the average of each column element of two rows (in a 2 dimensional array) and insert that average between the two rows
이전 댓글 표시
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
Wayne King
2014년 7월 24일
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
2014년 7월 25일
Allan N
2014년 7월 25일
답변 (3개)
Andrei Bobrov
2014년 7월 24일
out = sort([mean(x);x])
댓글 수: 1
Image Analyst
2014년 7월 25일
Works for that one case but won't work in general. Try it for this matrix:
m=[12,13,44;...
4,5,6]
dpb
2014년 7월 24일
편집: Andrei Bobrov
2014년 7월 24일
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
2014년 7월 25일
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')
카테고리
도움말 센터 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!