필터 지우기
필터 지우기

Track changes in the rows to get a new variable in Matlab

조회 수: 1 (최근 30일)
Maria
Maria 2014년 8월 9일
댓글: Azzi Abdelmalek 2014년 8월 9일
I have a double variable called 'change2' with 3 columns and 40000 rows. The variable is sorted by c2 and then date (c1).
c1 c2 c3
change2=[2009 1 42
2010 1 42
2011 1 559
1995 12 100
2000 12 100
2000 12 111
2003 12 100...]
I would like to get a new variable that has the first row in which a code from c2 appears for the first time and then the rows in which you observe a change in c3 for the same c2. For instance:
c1 c2 c3
change2=[2009 1 42
2011 1 559
1995 12 100
2000 12 111
2003 12 100...]
Can someone help? Thanks
  댓글 수: 2
Azzi Abdelmalek
Azzi Abdelmalek 2014년 8월 9일
편집: Azzi Abdelmalek 2014년 8월 9일
What if
change2=[2009 1 42
2010 1 42
2011 1 559
1995 12 100
2000 12 100
2000 12 111
2000 12 141
2000 15 124
2003 12 100]
Maria
Maria 2014년 8월 9일
That is impossible. Your last row would have to be next to the other rows that have in c2 the value 12. So changing the order of your two last rows, I would get:
change2=[2009 1 42
2011 1 559
1995 12 100
2000 12 111
2000 12 141
2003 12 100
2000 15 124
]

댓글을 달려면 로그인하십시오.

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2014년 8월 9일
편집: Azzi Abdelmalek 2014년 8월 9일
Edit2
change2=[2009 1 42
2010 1 42
2011 1 559
1995 12 100
2000 12 100
2000 12 111
2000 12 111
2000 12 141
2003 12 100
2003 15 124]
c2=change2(:,2);
c3=change2(:,3);
ii=[1 ;diff(c2)~=0]
jj=[1 ;diff(c3)~=0]
change2(~any([ii jj],2),:)=[]
%or in one line
change2(~any([[1 ;diff(change2(:,2))~=0 ] [1 ;diff(change2(:,3))~=0]],2),:)=[]
  댓글 수: 2
Maria
Maria 2014년 8월 9일
It goes through the variable and keeps for each year one row. If for instance I have this:
change2=[2007 1 42
2008 1 42
2009 1 42
1995 12 100
1996 12 101
1996 12 154 ]
I get:
change2=[2007 1 42
2008 1 42
2009 1 42
1995 12 100
1996 12 154 ]
And I would like to get:
change2=[2007 1 42
1995 12 100
1996 12 101
1996 12 154 ]
Changes may occur in the same year.
Azzi Abdelmalek
Azzi Abdelmalek 2014년 8월 9일
I have edited the answer

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by