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!