Error using plot, "vectors much be same length"

조회 수: 1 (최근 30일)
Kristine
Kristine 2022년 8월 6일
댓글: Kristine 2022년 8월 6일
I am getting the error:
Error using plot
Vectors must be the same length.
Error in HW11part1 (line 12)
plot(-1.5:0.1:1.5,Sxx)
Can you help me fix my code?Thank you!
Code:
L=1;
s=.75;
y=0;
icount = 0;
for xbar=-1.5:0.1:1.5
icount = icount + 1;
fun= @(tbar) ((xbar-tbar)^3)/(((xbar-tbar)^2+y^2)^2);
Sxx1=integral(fun,-L,-s, 'ArrayValued',1);
Sxx2=integral(fun,s,L, 'ArrayValued',1);
Sxx(icount)=(Sxx1+Sxx2);
end
plot(-1.5:0.1:1.5,Sxx)
xlabel('x/L')
ylabel('Normalized Sxx')

채택된 답변

Adam Danz
Adam Danz 2022년 8월 6일
Try,
x = linspace(-1.5, 1.5, numel(Sxx))
plot(x,Sxx)
  댓글 수: 1
Kristine
Kristine 2022년 8월 6일
Hmm, my graph is not what I expect. I am graphing now though. Thanks!

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

추가 답변 (0개)

카테고리

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

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by