필터 지우기
필터 지우기

How to plot a smoother graph or wave?

조회 수: 5 (최근 30일)
Ruzam
Ruzam 2015년 12월 19일
댓글: Star Strider 2015년 12월 20일
Ok, so I'm fairly new to matlab still. So given the code below I would like to plot a given equation within the loop. Unfortunatly It is only plotting in steps of 1 for w up to 100. Thats why it doesn't look smooth. However if I put w=1:0.1:N for the for loop, it then gives an error and says must be an integer, this makes sense because y(w) says we are accessing an element in an array. So then I just put y=2*sin(2*w)/w; and there is no graph displayed, just a white empty space.
Could I create an array like w=0:0.01:100; Maybe, and then...... arrghh, I can't think right now. The code is below.
N=100;
y=2*sin(2*w)/w;
for w=1:N
y(w)=2*sin(2*w)/w;
end;
%semilogx([1:N],y);
plot([1:N],y);
Any help would be greatly appreciated. Thank you.

채택된 답변

Star Strider
Star Strider 2015년 12월 19일
You first approach is best, although you need to vectorise the division (use ./ instead of /). You do not need the loop:
N=100;
w=1:0.1:N;
y=2*sin(2*w)./w;
plot(w,y);
See the documentation for Array vs. Matrix Operations for details on matrix and element-wise calculations.
  댓글 수: 2
Ruzam
Ruzam 2015년 12월 20일
편집: Ruzam 2015년 12월 20일
ahh yeah, I knew about the vectorise multiplication, however I just hadn't thought of ./ . Thank you!
Star Strider
Star Strider 2015년 12월 20일
My pleasure!

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by