Scanning Matrix For Changes In Polarity
    조회 수: 3 (최근 30일)
  
       이전 댓글 표시
    
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.
댓글 수: 0
채택된 답변
  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
추가 답변 (0개)
참고 항목
카테고리
				Help Center 및 File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

