Why this program keep saying Error using plotting>getC Too many output arguments. Error in plotting (line 9) res(i)=getC(1,0,100);? The getC returns c, which is only one output(a number),where're the 'too many' outputs?
古いコメントを表示
Here's my scripts,I'm new to Matlab and really couldn't figure out how to fix this problem...
function plotting
clc
close all
x = linspace(1,2,2);
res=zeros(1,length(x));
for i=1:length(x)
xpt=x(i);
res(i)=getC(1,0,100);
%res(i)=getC;
end
plot(x,res)
function getC(x,t,n)
c=0;
for k=1:1:n
c=c+(4*(-1).^k)/((2*k+1)*pi)*cos(((2*k+1)*pi)*x/2)*exp(((-(2*k+1)*pi)/2).^2*t);
end
getC = c;
回答 (2 件)
Walter Roberson
2017 年 8 月 7 日
Change
function getC(x,t,n)
c=0;
for k=1:1:n
c=c+(4*(-1).^k)/((2*k+1)*pi)*cos(((2*k+1)*pi)*x/2)*exp(((-(2*k+1)*pi)/2).^2*t);
end
getC = c;
to
function c = getC(x,t,n)
c=0;
for k=1:1:n
c=c+(4*(-1).^k)/((2*k+1)*pi)*cos(((2*k+1)*pi)*x/2)*exp(((-(2*k+1)*pi)/2).^2*t);
end
カテゴリ
ヘルプ センター および File Exchange で Axis Labels についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!