Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab 如何使用trapz函数与积分函数_Matlab_Integration_Fft_Performance - Fatal编程技术网

Matlab 如何使用trapz函数与积分函数

Matlab 如何使用trapz函数与积分函数,matlab,integration,fft,performance,Matlab,Integration,Fft,Performance,我的代码使用函数工作,但我希望使用函数来实现它 fc = 5*10^6; fb = 0.2*10^6; F = [0:10000:10^7]; Tb = 1/fb; Sequence = [0 1 0 1 1 0 1 1 1 0 0 0 1 0 1 ]; A = sqrt(9/Tb); w = 2*pi*fc; I = zeros(1,length(F)); for counter1 = 1:length(Sequence) if Sequence ( 1, counter1) == 1

我的代码使用函数工作,但我希望使用函数来实现它

fc = 5*10^6;
fb = 0.2*10^6;
F = [0:10000:10^7];
Tb = 1/fb;
Sequence = [0 1 0 1 1 0 1 1 1 0 0 0 1 0 1 ];
A = sqrt(9/Tb);
w = 2*pi*fc;
I = zeros(1,length(F));
for counter1 = 1:length(Sequence) 
if Sequence ( 1, counter1) == 1   
    s_of_t = @(t) A*cos(w*t)*exp(-1i*2*pi*t*F); 
else
    s_of_t = @(t) -A*cos(w*t)*exp(-1i*2*pi*t*F);
end
    S_of_f = integral(s_of_t,((counter1-1)*Tb),(counter1*Tb),'ArrayValued', true);
for counter2 = 1:length(S_of_f)  
    I( 1, counter2) = I(1,counter2)+S_of_f(1,counter2);
end
    clear S_of_f s_of_t;
end
figure(1)
plot(F,abs(I));
我想做的是使用trapz函数,而不是像这样的积分函数:

for n = 1 : length(F)
    S_of_f(n) = trapz(F,s_of_t);
end
而不是:

S_of_f = integral(s_of_t,((counter1-1)*Tb),(counter1*Tb),'ArrayValued', true);
我在使用这个函数实现我的代码时遇到了困难,所以如果您有任何建议,我将不胜感激

错误包括: 类型为“function\u handle”的输入参数的未定义函数“max”。 trapz中的错误(第43行) perm=[dim:max(ndims(y),dim)1:dim-1]

我不确定缺少哪个函数来处理


(是的,我正在使用傅里叶变换,但是我尝试使用函数占用了太多的内存)。

trapz
需要函数求值向量,而不是函数句柄,这正是
积分所需要的

if Sequence ( 1, counter1) == 1
        s_of_t = @(t,F) A*cos(w*t).*exp(-1i*2*pi*t*F);
    else
        s_of_t = @(t,F) -A*cos(w*t).*exp(-1i*2*pi*t*F);
    end
    for i=1:length(F)
        r=linspace(((counter1-1)*Tb),(counter1*Tb),100);
        S_of_f(i) = trapz(r,s_of_t(r,F(i)));
    end
  ...
我使用
trapz
为积分任意选择了100个评估点;您将希望根据使用此代码的方式将其修改为适当的值