필터 지우기
필터 지우기

Info

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

Which could be the smartest way to do what this function does

조회 수: 2 (최근 30일)
Salvatore Mazzarino
Salvatore Mazzarino 2013년 11월 12일
마감: MATLAB Answer Bot 2021년 8월 20일
I should have to graph step discret signal. This is the function.
function y = step(a,b,n0,flag)
n = a:b;
y = zeros(1,length(n));
if flag == 0
y(find(n==n0):length(n)) = 1;
else
y(1:find(n==n0)) = 1;
end
stem(n,y), grid on;
xlabel('n');
ylabel('u[n]');
return
Do you think it exists a smarter way to create what I have done wihtout using the if clause?

답변 (1개)

Roger Stafford
Roger Stafford 2013년 11월 12일
n = a:b;
y = double(((n>=n0)&(flag==0))|((n<=n0)&(flag~=0)));
  댓글 수: 2
Salvatore Mazzarino
Salvatore Mazzarino 2013년 11월 12일
Do you think it exist a way without using the flag?
Roger Stafford
Roger Stafford 2013년 11월 12일
As you have the 'step' function defined, the 'flag' input is essential for determining whether it is the beginning portion of a:b or its end portion that is set to 1's. How could you do that "without using the flag"?

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by