How to extract multiple matrices of different dimensions from a large matrix?
Ältere Kommentare anzeigen
Hello everyone,
I'm having troubles trying to extract multiple smaller sized matrices from a huge matrix.
Situation:
1. I have a matrix of dimension matrix(110848,15) - everything numeric matrix(:,1) - the first row of the matrix contains a time-stamp (in miliseconds for 15 minutes). matrix(:,2:15) contain numeric values of something I measured.
2. I have another column vector which contains exact points in time (time-stamps) at which I want to break the above mentioned matrix: time(125,1). 125 is given as example.
time(1,1)=5;
time(2,1)=7.5;
time(3,1)=12.5;
time(4,1)=15;
time(5,1)=20;
time(6,1)=22.5;
time(7,1)=27.5;
time(8,1)=30;
time(9,1)=35;
time(10,1)=37.5;
time(11,1)=42.5;
time(12,1)=45;
etc.
This sequencing from 5 to 2.5 seconds goes on for the equivalent of 15 minutes.
Let's say I want to extract all data from matrix for the first 5 seconds which go from row1 (second=0) to row641 (second=5) in a different matrix, call it matrix_period1. So matrix_period1 will initially have 641 observations for 15 columns. As such, time(1,1) = 5 and matrix(641,1) = 5.
In matrix_period2, I want to have all observations from matrix(642:j,1) for which time(j=2,1) - hence for the second observation of time (7.5 seconds).
In matrix_period3, I want to have all observations from matrix(j:next,1) for which time(j=next,1) - hence for the third observation of time (12.5 seconds).
And so on... for all 8 matrices.
However, after going through all matrices for 8 periods, matrix_period1 will have to take values from matrix(j=last_period from matrix_period8,1) - hence the 9th observation of time.
The process repeats itself.
Does anyone have any idea on how to help me?
I can provide more information of course if I was not clear.
Thank you!
3 Kommentare
Andrew Shum
am 13 Jun. 2017
So let me see if I understand correctly. Your data is in one giant matrix. In a vector, you have times which indicate the end of each data set. You want to separate the data sets into groups such that a group contains every 8th data set.
Mihai Toma
am 23 Jun. 2017
Stephen23
am 27 Jun. 2017
Identify the groups using division and rounding (or whatever other method that suits your needs), then use mat2cell or accumarray to split the matrix into matrices in a cell array. A search of this forum will find hundreds of threads discussing how to split a numeric matrix into smaller matrices, e.g.:
Do NOT waste your time writing bad code that creates separate variables with numbered variable names: "A frequent use of the eval function is to create sets of variables such as A1, A2, ..., An, but this approach does not use the array processing power of MATLAB and is not recommended."
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Logical finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!