how to find difference between column elemnts in a matrix ?
조회 수: 12 (최근 30일)
이전 댓글 표시
Let my matrix is
3 2 14 5
7 1 8 9
11 11 12 13
I need to find the substraction between column 1 and 2 and store the result in coulmn 1. similarily for coulmn 3 and 4 and result will be in coulmn 2. i.e the result should be like this
1 9
6 -1
0 -1
kindly, suggest solution. Thank you.
댓글 수: 0
채택된 답변
Stephen23
2017년 6월 13일
편집: Stephen23
2017년 6월 14일
A general solution (without hard-coded columns):
>> M(:,1:2:end) - M(:,2:2:end)
ans =
1 9
6 -1
0 -1
EDIT: if you have uint8 image data, then convert to double first:
double(M(:,1:2:end)) - double(M(:,2:2:end))
댓글 수: 6
Walter Roberson
2017년 6월 13일
double(M(:,1:2:end)) - double(M(:,2:2:end)) would run less risk of overflowing datatypes
추가 답변 (1개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!