How to solve "Not enough input arguments."

조회 수: 2 (최근 30일)
Dimitra
Dimitra 2023년 5월 5일
답변: Jon 2023년 5월 8일
function pinaka = pendatiagonal(e,c,d,a,b)
pinaka = pendatiagonal(e,c,d,a,b)
n = 7;
e = [0 0 round(10*rand(1,n-2))+1];
c = [0 round(10*rand(1,n-1))+1];
d = round(10*rand(1,n))+1;
a = [round(10*rand(1,n-1))+1 0];
b = [round(10*rand(1,n-2))+1 0 0];
e = e(3:end);
c = c(2:end);
a = a(1:end-1);
b = b(1:end-2);
diag(e,-2) + diag(c,-1) + diag(d,0) + diag(a,1) + diag(b,2);
disp(pinaka)
end
  댓글 수: 2
Jon
Jon 2023년 5월 5일
It isn't clear at all what you are doing here.
It looks like you start out defining a function call pendatiagonal, but then in the next line you call it, then you start assigning the input variable you would need for calling this function. What exactly are you trying to do, please explain further.
Torsten
Torsten 2023년 5월 5일
@Dimitra comment moved here:
Hi,
i try to make a pendatiagonal matrix, which has zeros in all columns except the main diagonal and the 2 lines above and below it. The problem is that, when i run it , it says that
"Not enough input arguments."

댓글을 달려면 로그인하십시오.

답변 (2개)

cdawg
cdawg 2023년 5월 5일
you're creating e, c, d, a, and b within the function.. it looks like n could be the only input. is this what you're trying to do?
n = 7;
pinaka = pendatiagonal(n)
pinaka = 7×7
9 2 1 0 0 0 0 7 7 4 3 0 0 0 9 8 3 5 6 0 0 0 8 10 5 10 9 0 0 0 3 5 3 9 3 0 0 0 1 6 9 4 0 0 0 0 3 1 10
function pinaka = pendatiagonal(n)
e = [0 0 round(10*rand(1,n-2))+1];
c = [0 round(10*rand(1,n-1))+1];
d = round(10*rand(1,n))+1;
a = [round(10*rand(1,n-1))+1 0];
b = [round(10*rand(1,n-2))+1 0 0];
e = e(3:end);
c = c(2:end);
a = a(1:end-1);
b = b(1:end-2);
pinaka = diag(e,-2) + diag(c,-1) + diag(d,0) + diag(a,1) + diag(b,2);
end

Jon
Jon 2023년 5월 8일
You could also do it all with a very simple loop
pentadiagonal(7)
ans = 7×7
1 3 6 0 0 0 0 6 2 7 8 0 0 0 7 3 5 1 4 0 0 0 4 8 6 3 2 0 0 0 4 9 8 7 3 0 0 0 10 6 6 4 0 0 0 0 7 9 1
function pinaka = pentadiagonal(n)
pinaka = zeros(n,n);
for k = -2:2
pinaka = pinaka + diag(randi(10,n-abs(k),1),k);
end
end

카테고리

Help CenterFile Exchange에서 Operating on Diagonal Matrices에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by