how to fill a matrix using the rows of another matrix
Mostra commenti meno recenti
I have a matrix A of size 8540X18, there is a specific column in that matrix that its whenever the next row is less than the previous row, we need to extract all the rows before that row and store them in another matrix B and then store that matrix in a seperate data file. anybody can help with this?
7 Commenti
Walter Roberson
il 12 Set 2021
So if every 100'th row had that happen, then you would want rows 1 to 99 saved in B at the time row 100 was looked at, and store that in a file, and then when row 200 was encounted, you would want rows 1 to 199 saved in B including the row at 100 that triggered the previous save... and so on, with each time it storing a larger and larger extract, because you said all rows before that row?
Or do you only want to store in the sections, saving each block of increases-only ?
What do you want to have happen if two rows beside each other decrease? like 1, 3, 5, 4 (decrease relative to 5), 2 (decrease relative to 4) ?
MA
il 12 Set 2021
Find the breakpoints with
idxBkpt=find(diff[0 A.GDALT])<0);
and then process the array of breakpoints with a loop -- first pass the first location is 1, second pass it is idxBkpt(i-1)
But, if the spacing is the same, then you can simply reshape() the data based on the length of the one vector.
Walter Roberson
il 12 Set 2021
I agree, if the spacing is the same every time then reshape(). Possibly followed by permute()
permute(reshape(A.GDALT, spacing, [], size(A.GDALT,2)), [1 3 2])
this would produce a (spacing) by (columns) by (number of groups) array.
If the spacing is not the same every time, then instead of a loop, you can use diff() of find() to get the size of each block, and then you can use mat2cell() to break the matrix up into chucks that size.
MA
il 13 Set 2021
Walter Roberson
il 13 Set 2021
idxBkpt = find( diff[0;A.GDALT]) < 0 );
MA
il 13 Set 2021
Risposte (1)
Salman Ahmed
il 14 Ott 2021
Hi manar,
From the comments, I understand that you wish to segregate your data into different cells whenever you hit peaks in your data. You could try the following operations on your data:
idx = find(diff([0;A.GDALT])<0); % Finding the breakpoints
B = mat2cell(A,[idx(1)-1;diff(idx);numel(A.GDALT)-idx(end)+1]); % Segregating the tables
Hope it solves your issue.
Categorie
Scopri di più su Logical in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!