How to solve "Not enough input arguments."

1 次查看(过去 30 天)
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 中查找有关 Fourier Analysis and Filtering 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by