[討論] [求救]nargin讀不出來

看板MATLAB作者 (CWALK)時間13年前 (2012/03/20 23:24), 編輯推噓0(003)
留言3則, 2人參與, 最新討論串1/1
是這樣的,我的題目是: 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

03/21 00:32, , 1F
你的function在哪裡?
03/21 00:32, 1F

03/21 07:50, , 2F
nargin在function M-file中才會正常動作,在script中用
03/21 07:50, 2F

03/21 07:51, , 3F
的話數值很詭異,你可以自己試試。
03/21 07:51, 3F
文章代碼(AID): #1FQA4eAw (MATLAB)