필터 지우기
필터 지우기

Hi, I am new to MATLAB. I am not getting the plot .

조회 수: 1 (최근 30일)
Kshitija Bagde
Kshitija Bagde 2018년 2월 28일
댓글: Jim Riggs 2018년 2월 28일
I am trying to plot N=5; A=-20:5:20; B=(1/N)*(abs((sin((N*A)/2))/(sin(A/2)))); plot(A,B)
I am not getting any error but getting only one value for B. Help please. Thank You in advance

채택된 답변

Chad Greene
Chad Greene 2018년 2월 28일
You're doing vector operations, so use the ./ when calculating B like this:
B=(1/N)*(abs((sin((N*A)/2))./(sin(A/2))));
The . before operators such as .* is the difference between a cross product and a dot product, and the same logic follows for division and exponentials.

추가 답변 (1개)

Jim Riggs
Jim Riggs 2018년 2월 28일
Inside the abs function you are dividing two vectors. This is where the error is.
  댓글 수: 2
Kshitija Bagde
Kshitija Bagde 2018년 2월 28일
But when manually calculated, for every value A, there is different answer. Also not getting when abs is deleted
Jim Riggs
Jim Riggs 2018년 2월 28일
You should review your Matlab introductory material for operation syntax. Matlab uses different syntax to determine when a matrix operation is to be performed (as you have specified) vs. a scalar operation (as Chad has shown in his answer). You need to be familiar with these concepts.

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by