can any one tell me why that function can not run??

조회 수: 1 (최근 30일)
Hasnaa Hasaan
Hasnaa Hasaan 2022년 12월 8일
이동: John D'Errico 2022년 12월 8일
n=-5:5;
x=y(n);
x1=y(n-1);
x2=y(n+1);
subplot(3,1,1)
stem(n,x);
grid on;
subplot(3,1,2)
stem(n,x1);
grid on;
And I have the following function
function x=y(n)
x(n)=(n).*(n>=1&n<=5);
end
  댓글 수: 1
Hasnaa Hasaan
Hasnaa Hasaan 2022년 12월 8일
이동: John D'Errico 2022년 12월 8일
Thank you all for you cooperation

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

채택된 답변

Stephen23
Stephen23 2022년 12월 8일
편집: Stephen23 2022년 12월 8일
x(n) = ..
^^^ because of this indexing
Fixed:
n=-5:5;
x=y(n);
x1=y(n-1);
x2=y(n+1);
subplot(3,1,1)
stem(n,x);
grid on;
subplot(3,1,2)
stem(n,x1);
grid on;
function x=y(n)
x = (n).*(n>=1&n<=5);
end

추가 답변 (1개)

Jiri Hajek
Jiri Hajek 2022년 12월 8일
Hi, you obviously did not do any debugging. Your attempt at coding has several issues, but you can easily rectify them if you go obe line of the code at a time and have a look at its result. Matlab provides you a preview of the values of variables and you have the workspace panel with all your variables, where you can see all variables that currently... Use F10 or F11 to step through your code and see the results line by line. It will become much clearer.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by