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
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.
回答(2 个)
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)
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
0 个评论
Jon
2023-5-8
You could also do it all with a very simple loop
pentadiagonal(7)
function pinaka = pentadiagonal(n)
pinaka = zeros(n,n);
for k = -2:2
pinaka = pinaka + diag(randi(10,n-abs(k),1),k);
end
end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Fourier Analysis and Filtering 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!