How do i reshape the matrix from 2D- 3D?

I have a matrix 6x1000 double in matlab.How can i convert it to 3D as 6x1000x1 format ?
My input is times series data and i need to give it to sequence input layer for performing convolution.
I have tried
B=reshape(X,6,1000,1);
It didnt give errors, but B appeared same as 6 x 1000 double.
Input size of sequence input layer is given as 6 x 1000 x1.
and without reshaping/converting i am getting the below error while executing.
Invalid training data. Sequence responses must have the same sequence length as the
corresponding predictors.

6 Comments

What are the sizes of the sequence and predictors?
Matlab will hide trailing singleton dimensions. A 6x1000x1 array is stored the exact same way in memory as a 6x1000 array, because they are the same thing. So your error must come from a slightly different part.
All 1 dimensions beyond the 2nd dimension are not explicitly stored in MATLAB variables. That is, a 2x3x1 and a 2x3x1x1x1 variable will both be stored simply as a 2x3 variable. MATLAB will clip those trailing 1's automatically. Calling reshape( ) or similar functions will not change this result ... the trailing 1's will still be clipped.
I have applied this reshape command and tried.Still i am getting the same error.
@Rik Size of matrix is 6 x 1000
Stephen23
Stephen23 on 25 May 2021
Edited: Stephen23 on 25 May 2021
"I have a matrix 6x1000 double in matlab.How can i convert it to 3D as 6x1000x1 format ?"
They are already exactly the same arrays:
"Arrays in MATLAB are N-dimensional, with an infinite number of trailing singleton dimensions."
The infinite trailing singleton dimensions might not be displayed, but implicitly they are always there. See also:
The error message spoke of two things: response and predictor. You only mention one size.

Sign in to comment.

Answers (0)

Asked:

NN
on 25 May 2021

Commented:

Rik
on 25 May 2021

Community Treasure Hunt

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

Start Hunting!