Removing leading values in a matrix

2 次查看(过去 30 天)
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