when I enter n = 10, it reports an error Invalid second data argument

function f=vedangsong()
syms t n i w f(t)
Ao=input('nhap Ao: ');
n=input('nhap so bac hai n: ');
w=input('nhap tan so goc w: ');
for i = 1:n
tb1=['nhap A',num2str(i),': ' ];
A(num2str(i))=input(tb1);
tb2=['nhap B',num2str(i),': ' ];
B(num2str(i))=input(tb2);
end
f(t)=0
for i=1:n
s=sin(2*pi*i*w*t)
c=cos(2*pi*i*w*t)
g= A(num2str(i))*s + B(num2str(i))*c
f(t)=f(t) + g
end
f(t) =Ao + f(t)
t=linspace(0,1/w,300)
plot(t,f(t),'k')
title('Dang song trong mien thoi gian')
xlabel('Truc t')
ylabel('f(t)')
legend('f(t)')
end

댓글 수: 2

What input values should we use to test with?
Note that your statement
B(num2str(i))=input(tb2)
will not create variables named B1, B2, B3, and so on. Instead, it will be assignments to B('1'), B('2'), B('3') and so on, which is the same as assigning to B(49), B(50), B(51)
This is not a good sign:
B(num2str(i)) = ...
Dynamically creating or accessing variable names is one way that beginners force themselves into writing slow, complex, buggy code. Read this to know why:
You should just use indexing. Indexing is simple, neat, easy to debug, and very efficient (unlike what you are trying to do).

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

 채택된 답변

Nguyen trieu
Nguyen trieu 2019년 4월 26일

0 개 추천

thanks you! finally I have done my homework

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Graphics Performance에 대해 자세히 알아보기

태그

질문:

2019년 4월 25일

답변:

2019년 4월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by