How can I convert 2D matrix into a sequence?

I need to convert a matrix into a sequence. I have performed PCA on it and obtained 6 principle components. The PC1 contains almost 51 percent information. PC1 and PC2 contains 99% information. Is there any way that I can use PC1 and PC2 as a sequence in a sequence classifier or generate a sequence from above mentioned matrix. Anyone can give any hint or idea please.

2 Comments

for PCA reconstruction, look into here. Also have a look into the answer's comments
Rab Nawaz
Rab Nawaz on 30 Nov 2022
Edited: Rab Nawaz on 30 Nov 2022
@Jonas, Thanks for your comments, I check it out.

Sign in to comment.

Answers (1)

Assuming the data to be time series or sequential data, we can depict the matrix data as sequence data as follows:
Using the 1800x2 PCA Matrix (from Principal components PC1 and PC2)
1.Treat each row (i.e. one time step of PC1 and PC2) as an input to your sequence model:
% Example PCA data
PCA_data = rand(1800, 2); % Dummy data
% Convert to sequence: each row becomes a 1×2 sequence
sequenceData = mat2cell(PCA_data, ones(1800, 1), 2);
Output: a 1800×1 cell array, each cell is a 1×2 vector like [PC1, PC2].
You now have a proper input format for sequence models, where each time step is a feature vector [PC1, PC2]
2. Add labels as necessary (for classification).
labels = categorical(randi([1, 2], 1800, 1)); % Dummy binary labels
3.Train on any sequence classifier like LSTM.
For more clarifications refer to the following official MathWorks documentation links:
  1. PCA: https://www.mathworks.com/help/stats/pca.html
  2. Sequence classification using deep learning: https://www.mathworks.com/help/deeplearning/ug/classify-sequence-data-using-lstm-networks.html
Hope this helps you!

Categories

Products

Release

R2019a

Asked:

on 30 Nov 2022

Answered:

on 12 Jun 2025

Community Treasure Hunt

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

Start Hunting!