필터 지우기
필터 지우기

Error in the specification of the window when using movmad

조회 수: 9 (최근 30일)
Tiago Dias
Tiago Dias 2018년 6월 6일
댓글: Walter Roberson 2018년 6월 7일
Hello,
I got a matrix called "A" [nxm], where n is the number of observations and m is the number of variables.
I want to perform a movmean and movmedian, but instead of use the size of the window kb and kf the same for all the variables, i created a matrix B [1xm], with the values of "k" to use for each variable of the matrix table
the code to do this should be?
n = 969120;
m = 41;
result1 = NaN(n,m);
result2 = NaN(n,m);
for j = 1:m
for j = 1:n
result1(i,j) = movmad(A(i,j),[B(1,j) B(1,j)],'omitnan');
result2(i,j) = movmedian(A(i,j),[B(1,j) B(1,j)],'omitnan');
end
end
because when i run this in a script, i get the following error:
"error using movmad, window length must be a finite positive scalar or 2-element vector of finite nonnegative scalars"
  댓글 수: 7
Walter Roberson
Walter Roberson 2018년 6월 6일
You still have the difficulty that you appear to be apply movmad() and movmedian() to scalar numerics.
Tiago Dias
Tiago Dias 2018년 6월 6일
i don't understand that, could you use an example?

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

답변 (1개)

Walter Roberson
Walter Roberson 2018년 6월 6일
편집: Walter Roberson 2018년 6월 6일
if any(isnan(B)) || any(B(<0)) || any(B~=floor(B))
error('B must be non-negative integers');
end
n = 969120;
m = 41;
result1 = NaN(n,m);
result2 = NaN(n,m);
for i = 1:n
result1(i,:) = movmad(A(i,:), [B(i) B(i)], 'omitnan');
result2(i,:) = movmedian(A(i,:), [B(i) B(i)], 'omitnan');
end
  댓글 수: 2
Tiago Dias
Tiago Dias 2018년 6월 6일
Perhaps i am mistaken, but what i want to do is to applot movmad for the 1st column of A with the 1st value of B, then movmad to the 2nd column of A the 2nd value of B.
and what o wrote applies in rows no?
Walter Roberson
Walter Roberson 2018년 6월 7일
if any(isnan(B)) || any(B(<0)) || any(B~=floor(B))
error('B must be non-negative integers');
end
n = 969120;
m = 41;
result1 = NaN(n,m);
result2 = NaN(n,m);
for i = 1:m
result1(:,i) = movmad(A(:,i), [B(i) B(i)], 'omitnan');
result2(:,i) = movmedian(A(:,i), [B(i) B(i)], 'omitnan');
end

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by