作者timche2 (CWALK)
看板MATLAB
标题[讨论] [求救]nargin读不出来
时间Tue Mar 20 23:24:21 2012
是这样的,我的题目是:
Let x and y be column vectors describing the vertices of a polygon, given in
order. Write
functions polyperim(x,y) and polyarea(x,y) that compute the perimeter and
area of the polygon. For the area, use a formula below
http://twpic.org/uploads/43f9f3ad21.bmp
in which n is the number of polygon vertices, and by definition
我想说先输入所有x座标 y座标 再来算
程式码如下
n = input('number of polygon?')
xm = sparse(1,n)
ym = sparse(1,n)
cntx = 1
cnty = 1
while n< 1e+1000
xm(cntx) = input('enter x, enter to end')
%-------------------可是到这行就不能读取了-----------------
if nargin==0
ym(cnty) = input('enter y, enter to end')
cnty = cnty + 1
if nargin == 0
for cntx = 1:n
for cnty = 1:n
polyarea = 0.5*abs(xm(cntx)*y(cnty+1)-x(cntx+1)*y(cnty))
end
end
end
end
cntx = cntx + 1
end
想请问各位大大可以帮我看一下吗QAQ
感恩~
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.112.7.214
1F:→ kdjf:你的function在哪里? 03/21 00:32
2F:→ mp19990920:nargin在function M-file中才会正常动作,在script中用 03/21 07:50
3F:→ mp19990920:的话数值很诡异,你可以自己试试。 03/21 07:51