Scanning Matrix For Changes In Polarity

2 ビュー (過去 30 日間)
Harry Eggo
Harry Eggo 2016 年 8 月 23 日
コメント済み: Harry Eggo 2016 年 8 月 23 日
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.

採用された回答

Robert
Robert 2016 年 8 月 23 日
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 件のコメント
Harry Eggo
Harry Eggo 2016 年 8 月 23 日
Thank you, Robert! This is exactly what I was looking for.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOperators and Elementary Operations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by