Removing leading values in a matrix

조회 수: 2 (최근 30일)
Stephen Thompson
Stephen Thompson 2017년 9월 18일
편집: dpb 2017년 9월 19일
I am using the findchangept function ('std') on the below time series. The first 23 values are 0, which gets marked as the changepoint by the function (left plot). If I detect the first non-zero entry (find(x, 1)) and then analyse the data from that point onward that function works much better (right plot). My problem is in replicating this across a large matrix of data.
The matrix is 200x10000, but the first non-zero entry varies by row. I don't know how to adjust the matrix so that each row is of a different length. I'm actually using the data in a cell framework so:
%first non_zero point in each cell
first_non_zero = cellfun(@(x)(find(x, 1)), example_cell);
This yields a 200 x 1 matrix.
example_cell_adjust (i) = example_cell (i, (first_non_zero(i): end));
This doesn't work but shows what I want, a set of vectors of unequal length that I can then run the findchangept function on.
Or maybe there is a better way of using the findchangept function so that it doesn't trip on the first zero to non-zero point.
Thanks.

채택된 답변

dpb
dpb 2017년 9월 19일
편집: dpb 2017년 9월 19일
Probably easiest is to just process each column in a loop...
for i=1:size(x,2) % over each column in x
iz=find(x(:,i),1); % first nonzero x location
res(i)=findchangept(x(iz:end,i)); % call the function wanted over those data
...
I don't know the findchangept function and didn't look it up to see what it returns; obviously preallocate for its output if saving for each column or use the result in the loop and go on to the next.
And, of course, you wouldn't necessarily have to have the temporaries as shown; put them here to illustrate the process more clearly.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Measurements and Statistics에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by