how to find difference between column elemnts in a matrix ?

21 ビュー (過去 30 日間)
aditya sahu
aditya sahu 2017 年 6 月 13 日
編集済み: Stephen23 2017 年 6 月 14 日
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.

採用された回答

Stephen23
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
Walter Roberson 2017 年 6 月 13 日
double(M(:,1:2:end)) - double(M(:,2:2:end)) would run less risk of overflowing datatypes
aditya sahu
aditya sahu 2017 年 6 月 14 日
Thank you @walter-roberson and @Stephen Cobeldick ,,i got it...my matrix was actually uint8 and i am expacting negative, sorry for my mistake..but thank you for your suggestion...

サインインしてコメントする。

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2017 年 6 月 13 日
Result = YourMatrix(:,[1 3]) - YourMatrix(:,[2 4])
  1 件のコメント
aditya sahu
aditya sahu 2017 年 6 月 13 日
Thank you, but suppose my matrix is 512*512 size then how to do?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by