-1

I have a 3d matrix in MATLAB (time x channel x trial) that I want to extend so that it is a 2D (time x channel) matrix of continuous data instead of data segmented into trials. The closest command I can find is 'reshape', but I am unsure how to properly use it.

Is reshape the best command to use? If so, can someone please provide me an example of how to use it in my situation?

SaraA
  • 33
  • 6
  • I don't have Matlab at hand right now, so try the following: if your 3d matrix has dimensions m x n x p , then try `reshape(your_matrix, m*p , n)`. – R. Schifini Jan 30 '16 at 23:13
  • 2
    Have you seen [this](http://stackoverflow.com/questions/2256925/reshape-3d-matrix-to-2d-matrix) answer? – R. Schifini Jan 30 '16 at 23:15
  • I did see that answer, thank you. I didn't quite understand the answer until you just restated it. This looks like it will work. Apologies for reasking the question. – SaraA Jan 30 '16 at 23:36
  • Actually, @R.Schifini, I implemented the suggestion and it doesn't seem like it worked correctly. When I index into the matrix I do not get the same values. Can you think of anything I could be doing incorrectly? For example, if my matrix was 100 x 10 x 5, if I use reshape(matrix, 100*5, 10) The value for matrix(1,1,2) is different than the value for the reshapedMatrix(101,1). They should be the same. – SaraA Jan 31 '16 at 00:37
  • 1
    Try `pmatrix = permute(matrix, [1 3 2]);` before you reshape. – beaker Jan 31 '16 at 00:45
  • 1
    @beaker - that worked! – SaraA Jan 31 '16 at 00:56

1 Answers1

0

Try something like this:

x = reshape( x, [Ntime, Nchannel*Ntrial] );
AnonSubmitter85
  • 933
  • 7
  • 14