Scanning Matrix For Changes In Polarity

2 visualizzazioni (ultimi 30 giorni)
Harry Eggo
Harry Eggo il 23 Ago 2016
Commentato: Harry Eggo il 23 Ago 2016
Just a bit of background: I have a very large matrix (106740x5). I need to process this into smaller files with a certain format to be compatible with other software. I have figured out how to produce the files in the right format but I've had another problem.
Basically, I need to break the files up so that if the changes in one of the column values changes direction (for example:
  • 1
  • 5
  • 12
  • 2 - 2 is less than 12 which contradicts the pattern of the previous values being bigger). When a direction change does occur, I need to break the matrix at this point and output it to a text file (which I know how to do).
Breaking the problem down, I can think of 2 main things that I need to know what to do to solve this problem:
  • Identifying how many times that the column changes direction
  • Identifying where these changes occur
There are other issues which I may come back to but I think that if I can figure out these parts, I will be able to sort things out.

Risposta accettata

Robert
Robert il 23 Ago 2016
You could use diff and sign to create a logical array, then cumsum to convert that to a group index.
% where x is your column of data
ddx = diff(sign(diff(x)))~=0;
group = cumsum([1;0;ddx])
for ii = 1:group(end)
isinthisgroup = group == ii;
% your processing, file writing
end
  1 Commento
Harry Eggo
Harry Eggo il 23 Ago 2016
Thank you, Robert! This is exactly what I was looking for.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Resizing and Reshaping Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by