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 CenterFile Exchange에서 Introduction 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