Subtracting pairs of adjacent columns in an array without overlap

2 ビュー (過去 30 日間)
Lisa Bunker
Lisa Bunker 2022 年 12 月 16 日
コメント済み: Lisa Bunker 2022 年 12 月 16 日
I am relatively new to Matlab and I am trying to get the difference between adjacent columns from an array where the columns alternate by condition (i.e., a contrast between experimental and control conditions). I have found code that on the surface seems to be what I am looking for (e.g., https://www.mathworks.com/matlabcentral/answers/743387-how-to-substract-every-two-adjacent-column-from-a-matrix?s_tid=srchtitle&s_tid=mwa_osa_a) but it actually calculates the difference for columns 1-2, 2-3, 3-4 , etc. but I want 1-2, 3-4, 5-6, etc. without any overlap.
e.g., a [72, 324]
b = a(:1:end-1) - a(:,2:end)
I am trying to get an output array with half the number of original columns (i.e., [72, 162])

採用された回答

Steven Lord
Steven Lord 2022 年 12 月 16 日
x = (1:10).^2
x = 1×10
1 4 9 16 25 36 49 64 81 100
y = x(:, 1:2:end)-x(:, 2:2:end)
y = 1×5
-3 -7 -11 -15 -19

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeIntroduction to Installation and Licensing についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by