Subtracting pairs of adjacent columns in an array without overlap

2 visualizzazioni (ultimi 30 giorni)
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])

Risposta accettata

Steven Lord
Steven Lord il 16 Dic 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

Più risposte (0)

Categorie

Scopri di più su Introduction to Installation and Licensing in Help Center e File Exchange

Prodotti


Release

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by