필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

It only shows the else value if value of b crosses 15 even once.

조회 수: 1 (최근 30일)
Adhish Aggarwal
Adhish Aggarwal 2017년 4월 19일
마감: MATLAB Answer Bot 2021년 8월 20일
b = AXIS(1:100,1) - KOTAK(1:100,1);
avg5 = zeros(5,1);
for k = 5:length(b)
avg5(k) = mean(b(k-4:k,1));
end
a = 0;
avg5 = [a;avg5];
avg5(numel(avg5),:) = [];
std5 = zeros(5,1);
for al = 5:length(b)
std5(al) = std(b(al-4:al,1));
end
% a = 0;
std5 = [a;std5];
std5(numel(std5),:) = [];
up5 = zeros(length(std5),1);
for d = 1 : length(std5)
if abs(b) < 14.5
up5(d) = std5*2 + avg5;
down5(d) = std5*(-2) + avg5;
else
up5(d) = std5*2 + avg5;
down5(d) = std5*(-2) + avg5;
end
end
It works well till up5 = zeros(length(std5,1));
  댓글 수: 3
Geoff Hayes
Geoff Hayes 2017년 4월 19일
Adhish - how is b set? Please post more of your code.
Adhish Aggarwal
Adhish Aggarwal 2017년 4월 19일
I have mine given my full code p above. Please let me know. Thank you

답변 (1개)

Steven Lord
Steven Lord 2017년 4월 19일
That's the correct behavior. From the documentation for the if keyword: " if expression, statements, end evaluates an expression, and executes a group of statements when the expression is true. An expression is true when its result is nonempty and contains only nonzero elements (logical or real numeric). Otherwise, the expression is false. "
In your case, you probably want to use logical indexing instead.
  댓글 수: 1
Adhish Aggarwal
Adhish Aggarwal 2017년 4월 19일
I have mine given my full code p above. Please let me know. Thank you

이 질문은 마감되었습니다.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by