# Derivative of cell with matrices

1 view (last 30 days)
Uerm on 10 Oct 2019
Edited: Uerm on 14 Oct 2019
Hi,
I have a variable X which is a 1x48 cell containing matrices of sizes Ax128. The number of A differs between the matrices. Basically, I want to calculate the derivative of each matrix individually along each row. How can I do that? If say, one of the matrices is 34x128, the end result of this matrix should be 34x127.

Stephen on 10 Oct 2019
Edited: Stephen on 10 Oct 2019
fun = @(m)diff(m,1,2);
out = cellfun(fun,X,'uni',0);
Uerm on 10 Oct 2019
Thank you very much. It works!

Uerm on 10 Oct 2019
Edited: Uerm on 10 Oct 2019
Thanks for the help! I have an additional question:
I have a variable y1, which is also a 1x48 cell. Each of these cells is a vector. y1 is a variable for ECG signals with 48 different patients/subjects.
The variable X from the initial question (1x48 cell with Ax128 matrices) contains segments. These segments should be applied to the ECG signal for each patient to segment the ECG signal.
Say X{1,1} is a 34x128 matrix and the first row (of the first matrix) of X has start and end values X{1,1}(1,1) = 370 and X{1,1}(1,end) = 37499
The first segment of the signal (first row of the first matrix) will therefore be y1{1,1}(X{1,1}(1,1):X{1,1}(1,end)). However, this should be done for each row and each patient. How can I do that?
Luna on 11 Oct 2019
Do you mean you want to fill y1 values with X{1,1}(1,1) : X{1,1}(1,end) ?
So for example y1{1,1} will be equal to [370:37499] ? Is it that or did I get wrong?

Uerm on 14 Oct 2019
Edited: Uerm on 14 Oct 2019
Well, sort of. I attach some screenshots of the variables and their content to make it easier to understand.
As you can see on image 1, y1 is a 1x48 cell each containing a 1x650000 double. Data_128 contains the R peaks of the ECGs in segments. So Data_128{1,1} is a 34x128 matrix - 34 segments of R peaks each containing 128 R peaks. I want to "segment" y1 based on the values in Data_128. So for patient 1, y1{1,1} should be divided in 34 segments. For patient 2 (y{1,2}), it is 28 segments etc. The first segment of y1{1,1} should be (in samples) [1:37499]. The second will be [19080:55908]. The third [37782:74473] etc. (basically from start of segment to end of segment). This should be done for all 48 patients. Hope the explanation helps.
{"found_math": false, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0}