Clear Filters
Clear Filters

Correlation between a 3D matrix and a vector

4 views (last 30 days)
Hello everyone, I have a 3D matrix (44x44x21 - channelsxchannelsxsubjects) and a vector of 21 elements (questionnaire answers for each subject). I would like to correlate the vector with all the cells of my 3D matrix. Of course I would like that answer for subject 1 (element 1 in the vector) is correlated with 44x44x1, answer for subj 2 with 44x44x2, etc... Is someone able to help me? Many thanks in advance
Chiara
  1 Comment
Jan
Jan on 8 Aug 2017
Some standard terms: "matrix" is a 2D array. Cells are cell arrays, which can contain non elementary data as elements. Therefore "3D matrices" do not contain "all cells".
What does "element 1 in the vector is correlated with 44x44x1" exactly mean?

Sign in to comment.

Accepted Answer

Chris Perkins
Chris Perkins on 8 Aug 2017
Hi Chiara,
If I understand your goal correctly, you will likely need to both re-arrange your data and expand the vector data into a 3D matrix.
To re-arrange your initial 3D matrix data, you can use the "permute" function, as shown below:
matrix = permute(matrix,[3 1 2]);
This allows you to change your 44x44x21 matrix to a 21x44x44 matrix, so the dimensions agree with the vector.
The documentation for the "permute" function is found at the following link: https://www.mathworks.com/help/matlab/ref/permute.html
Then, expand the vector to be a 21x44x44 matrix, where each element is expanded to be a 44x44 matrix of the same, repeated element.
Once the dimensions agree, you can follow the procedure to manually compute the standard Pearson coefficient, as described in the following MATLAB Answers question: https://www.mathworks.com/matlabcentral/answers/15884-correlation-for-multi-dimensional-arrays
  1 Comment
Brian DeCicco
Brian DeCicco on 1 Jul 2021
Hey Chris! I am trying to figure out a similar problem to this one, but am unsure how to "expand my vector to be a 3-D matrix, where each element is expanded to be a 1440x721 matrix of the same, repeated element". Can you assist? Thanks!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!