Subtracting pairs of adjacent columns in an array without overlap

2 Ansichten (letzte 30 Tage)
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])

Akzeptierte Antwort

Steven Lord
Steven Lord am 16 Dez. 2022
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

Weitere Antworten (0)

Kategorien

Mehr zu Introduction to Installation and Licensing finden Sie in Help Center und File Exchange

Produkte


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by