Not enough input arguments error

1 Ansicht (letzte 30 Tage)
Riley Morris
Riley Morris am 30 Aug. 2022
Beantwortet: Chunru am 30 Aug. 2022
function [tVec,xVec]=fxNthOrderPolysignal(domainVec, rootsVec)
% create time vector
tVec = linspace(domainVec(1),domainVec(2),100);
%obtain polynomial coefficients p from roots
p=poly(rootsVec);
% initialize to empty vector
xVec=[];
for c=1:length(tVec)
%val=f(tVec(c));
t = tVec(c);
val = polyval(p,t)
% if functional value is not numerix
% convert to numeric
if isnumeric(val)==false
val=eval(val);
end
% add in Xvec vector
xVec=[xVec val];
end
% plot the graph
plot(tVec,xVec);
xlabel('t values');
ylabel('x(t) values');
title('x(t) vs t');
grid on

Antworten (2)

Image Analyst
Image Analyst am 30 Aug. 2022
Bearbeitet: Image Analyst am 30 Aug. 2022
How are you calling it? For example are you doing this:
[tVec, xVec] = fxNthOrderPolysignal(1:10, [3,4,5,6]);
or some other way?
You're not just pushing the green run triangle are you? Because that will not send in input arguments to the function.

Chunru
Chunru am 30 Aug. 2022
% Call the function
[tVec,xVec]=fxNthOrderPolysignal([0 10], [1 2 3 2 1]);
% Define the function in the same file or separate file
function [tVec,xVec]=fxNthOrderPolysignal(domainVec, rootsVec)
% create time vector
tVec = linspace(domainVec(1),domainVec(2),100);
%obtain polynomial coefficients p from roots
p=poly(rootsVec);
% initialize to empty vector
xVec=[];
for c=1:length(tVec)
%val=f(tVec(c));
t = tVec(c);
val = polyval(p,t);
% if functional value is not numerix
% convert to numeric
if isnumeric(val)==false
val=eval(val);
end
% add in Xvec vector
xVec=[xVec val];
end
% plot the graph
plot(tVec,xVec);
xlabel('t values');
ylabel('x(t) values');
title('x(t) vs t');
grid on
end

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by