필터 지우기
필터 지우기

Ask for partitioning a matrix

조회 수: 1 (최근 30일)
Bundit Buddhahai
Bundit Buddhahai 2014년 4월 19일
댓글: Bundit Buddhahai 2014년 4월 28일
Hi, I have an input matrix of 2 columns data, the first column is time index data and the second one is data which represent the status of that number (which says, if the number is positive, the number label is ‘On’ whereas when the number is negative, the number label is ‘Off’). The process of ‘On’ (positive)/ ’Off’ (negative) for each number is time sequential data (data in the 2nd column) in which the frequency for ‘On’/ ‘Off’ state for each number is arbitrary. The ‘Off’ state for each number is the one which is the closest in time index to positive value of the same number.
Thank you. Bundit
I would like to make partitions of the input matrix to get positive/negative value that represent ‘On’/’Off’ state of each existing number in the matrix. The example is shown in the attached image

채택된 답변

Andrei Bobrov
Andrei Bobrov 2014년 4월 22일
편집: Andrei Bobrov 2014년 4월 24일
[~,~,c] = unique(abs(X(:,2)));
out = accumarray(c,(1:numel(c))',[],@(x){X(x,:)});
add
[a,~,c] = unique(abs(X(:,2)));
out = [a, accumarray(c,-sign(X(:,2)).*X(:,1))];
  댓글 수: 5
Andrei Bobrov
Andrei Bobrov 2014년 4월 25일
[a,~,c] = unique(abs(X(:,2)));
out = [a, accumarray(c,-sign(X(:,2)).*X(:,1))];
Bundit Buddhahai
Bundit Buddhahai 2014년 4월 28일
Many thanks Bobrov, your method is concise but very excellent. Great!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Types에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by