Insufficient input parameters.

function [Xm, faxis, xtw] = CalcFourierSpectrum (xt ,tmax, fmax, UseWindow )
%−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
dt = tmax/(length(xt)-1);%----<<< Insufficient input parameters. message here
t = 0: dt : tmax ;
%−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
xtw = xt ;
if ( UseWindow )
% window
fw = 1/ (2*tmax ) ;
% Hamming window
fw = 1 / ( tmax ) ;
w = 0.54-0.46*cos (2*pi*t / tmax ) ;
xtw = xt.*w;
end
% continuousf requency range
OmegaMax = 2*pi*fmax ;
dOmega = OmegaMax* 0.001 ;
%−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
fvec = [ ];
Xmvals = [ ];
p = 1;
for Omega = 0 : dOmega : OmegaMax
coswave = cos(Omega*t);
sinwave = -sin(Omega*t);
% perform the Four ier Transform v i a numerical i n t e g r a t i o n
Xreal = sum( xtw .*coswave*dt ) ;
Ximag = sum( xtw .*sinwave*dt ) ;
mag = sqrt (Xreal*Xreal + Ximag*Ximag ) ;
% s c a l e f requency to Hz , magnitude to maximum time
fHz = Omega/(2*pi);
mag = 2*mag/tmax ;
% save f requency and magnitude
faxis(p) = fHz ;
Xm(p) = mag ;
p = p + 1;
end
end

댓글 수: 6

Walter Roberson
Walter Roberson 2023년 5월 10일
When you press the green Run button to run the function, what is your expectation of where MATLAB will search for values to use for xt, tmax, fmax, and UseWindow ?
준영
준영 2023년 5월 10일
How can i fix that? this is my first time for Matlab. I don't know well
You are supposed to provide values as input for the code to run. See Declare Function name, inputs and outputs.
%Providing values as input
z = trig(pi/6,pi/3)
z = 0.5000
function z = trig(x,y)
z = 2.*sin(x).*cos(y);
end
준영
준영 2023년 5월 10일
where should I put into?
Walter Roberson
Walter Roberson 2023년 5월 10일
You should have other code that creates or calculates input values or requests information from the user about what data to use. And then that code should call CalcFourierSpectrum .
You should consider taking the MATLAB Onramp free course. https://matlabacademy.mathworks.com/details/matlab-onramp/gettingstarted
준영
준영 2023년 5월 10일
thank you.

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

답변 (1개)

Neeraj
Neeraj 2023년 5월 15일

0 개 추천

Hello,
As per my understanding, you are trying to call the function ‘CalcFourierSpectrum’. To do so you have to pass 4 input parameters: ‘xt ,tmax, fmax, UseWindow’. You will have to create these input parameters and store them in variables before calling the function ‘CalcFourierSpectrum’ with the respective variables as arguments.
Refer to the below documentation link for more details regarding function declaration:
If you are new to MATLAB I would highly recommend to take the MATLAB Onramp course:

카테고리

도움말 센터File Exchange에서 Descriptive Statistics and Visualization에 대해 자세히 알아보기

태그

질문:

2023년 5월 10일

답변:

2023년 5월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by