how to calculate element distance in a vector?
1 回表示 (過去 30 日間)
古いコメントを表示
hi guys i want to calculate the difference between vector element as [0 1 1 0 1 1 0] which should give 0-1=1,1-1=0,1-0=1,0-1=1,1-1=0,1-0=1,,, and the sum answer should be 4. how to do this. and what if there's 12 vector within one matrix.
0 件のコメント
採用された回答
W. Owen Brimijoin
2014 年 10 月 21 日
It looks like you want the sum of the absolute value of the differential of those numbers? You get your first answer like this:
abs_diff = abs(diff([0 1 1 0 1 1 0]))
You would then sum these values. If all you want is the final answer, this is how to do it:
answer = sum(abs(diff([0 1 1 0 1 1 0])))
3 件のコメント
W. Owen Brimijoin
2014 年 10 月 21 日
In order to answer this you would need to explain what you are looking for: one number per row, one per column, a giant sum (and if so in what dimension)?
その他の回答 (1 件)
参考
カテゴリ
Help Center および File Exchange で Resizing and Reshaping Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!