How to solve "Not Enough Input Arguments" Error?
이전 댓글 표시
I am trying to Write a function capable of displaying Pascal’s triangle for any number of rows to be specified as input.
My code is:
function pt = pascal_triangle(n)
% The first two rows are constant
pt(1, 1) = 1;
pt(2, 1 : 2) = [1 1];
% If only two rows are requested, then exit
if n < 3
return
end
for r = 3 : n
% The first element of every row is always 1
pt(r, 1) = 1;
% Every element is the addition of the two elements
% on top of it. That means the previous row.
for c = 2 : r-1
pt(r, c) = pt(r-1, c-1) + pt(r-1, c);
end
% The last element of every row is always 1
pt(r, r) = 1;
end
However, I get the following error:
Not enough input arguments.
Error in Draft1 (line 8)
if n < 3
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Argument Definitions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!