how to fill a matrix using the rows of another matrix

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

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) ?
thanks for replying back so quickly.
basiclly the last case you mentioned about two rows beside each other deacrese will not accur in our set of data. The data is said to start increasing from a starting point untill it reach to its maximum and then it will go back to the starting point and it basically represents some curve.
ex: if the strating point is 150 it will go 150, 250,350, 400, 550, ..., 850 (the maximum) ,150 , 250,350 and so on....
now I want to seperate each data set from its starting point to its maximum, menaning If the starting point was at the 1st row and at the 100th row we had the maximum point we need the data from the 1st row to the 100 to be stored in B then extract it to a separate file. then after the maximum point the data will go back to the starting point so if we had the next starting point at the 101 row and the maximum at the 200 row, we want to store from 101 to 200 in another matrix and extract that to another file.
If it would help more I attached the data set I have which I am representing it as a matrix in matlab, look at the column 12 under the heading GDALT
dpb
dpb il 12 Set 2021
Modificato: dpb 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.
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.
thank you very much for replying to my question, first @dpb when I tried this line 'idxBkpt=find(diff[0 A.GDALT])<0);' it gives me an error that says 'Dimensions of arrays being concatenated are not consistent'. and I am not sure how to fix that.
I want to mention that to read the data file, I am using the import data tool and then used the script generated by matlab I am not sure if that might be the reseaon of the error, I am just a bigenner in matlab.
idxBkpt = find( diff[0;A.GDALT]) < 0 );
Thank you for the help, I tried it now and it works perfectly fine. but now since I am dealig with a huge data set and the blocks we are trying to extract are having diffrenet sizes, how can I implement that using mat2cell?

Accedi per commentare.

Risposte (1)

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.

Prodotti

Release

R2021a

Richiesto:

MA
il 12 Set 2021

Risposto:

il 14 Ott 2021

Community Treasure Hunt

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

Start Hunting!

Translated by