필터 지우기
필터 지우기

Help with cusum and cellfun

조회 수: 3 (최근 30일)
Stephen Thompson
Stephen Thompson 2017년 5월 19일
답변: Greg Dionne 2017년 6월 8일
I am running the cusum function via cellfun as below - however I can only get one value from the output. When run separately, cusum outputs an [iupper,ilower] however running it via cellfun generates only one value, presumably the second change whether upper or lower. I am interested in first change - so either a way of getting that as an output or getting both as an output.
I hope this is clear. Thanks.
output = cellfun(@shift_time, input, 'UniformOutput', false);
function y = shift_time(x)
y = cusum(x, 100, 10, 0, 1);
end

채택된 답변

Walter Roberson
Walter Roberson 2017년 5월 19일
It would not be "the second change" that you got in that case: it would be the first output argument.
output = cellfun(@shift_time, input, 'UniformOutput', false);
function upper_lower = shift_time(x)
[iupper, ilower] = cusum(x, 100, 10, 0, 1);
upper_lower = {iupper, ilower};
end
  댓글 수: 1
Stephen Thompson
Stephen Thompson 2017년 5월 19일
That doesn't seem to be it - let me explain it again.
I have a 200X1 cell, each entry with 60000 points. Running cusum on one entry produces this (figure). There are two change point detection, upper and lower limits. In this case, it is the lower limit change point that I am interested in, the first detection, but the first detection might also be the upper limit change point in other data sets.
I want to replicate the cusum function across the whole dataset. It need not necessarily be via cellfun. The output will have to include both the upper and lower limits so that I can preserve both and later pick the first one.
I hope this is clear.

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

추가 답변 (1개)

Greg Dionne
Greg Dionne 2017년 6월 8일
I realize this may be a bit late, but in case someone else is looking for a solution, this worked for me:
% make some random data
a{1} = cumsum(randn(100,1));
a{2} = cumsum(randn(200,1));
a{3} = cumsum(randn(300,1));
a{4} = cumsum(randn(400,1));
a{5} = cumsum(randn(500,1));
% get first upper and lower breakouts
[iupper, ilower] = cellfun(@(x) cusum(x, 100,10,0,1), a, 'UniformOutput',false)
% get first breakout (if it exists)
ifirst = cellfun(@getfirst, iupper, ilower, 'UniformOutput',false)
function ifirst = getfirst(iupper, ilower)
if isempty(iupper)
ifirst = ilower;
elseif isempty(ilower)
ifirst = iupper;
elseif iupper < ilower
ifirst = iupper;
else
ifirst = ilower;
end
end
Output (you may get different results due to randn(), but hopefully they make sense)
iupper =
1×5 cell array
{0×1 double} {0×1 double} {[166]} {[363]} {0×1 double}
ilower =
1×5 cell array
{0×1 double} {[31]} {0×1 double} {[189]} {[43]}
ifirst =
1×5 cell array
{0×1 double} {[31]} {[166]} {[189]} {[43]}

카테고리

Help CenterFile Exchange에서 Audio and Video Data에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by