如何自动拟合此Matlab绘图?

如何自动拟合此Matlab绘图?,matlab,graph,plot,scale,Matlab,Graph,Plot,Scale,从代码中可以看出,我正试图从graph中获取图形结果……但当它输出时,我会在命令窗口中获取值,但图中显示了一条直线@零……我如何在这里自动缩放y轴???我不认为自动缩放是问题所在,而是事件序列 您尝试在此行中“初始化”绘图: function [h,w,y,graph] = lowpassFIR(sample) %Calculates Finite Impulse Response low pass filter coefficient %using the windowing methods

从代码中可以看出,我正试图从graph中获取图形结果……但当它输出时,我会在命令窗口中获取值,但图中显示了一条直线@零……我如何在这里自动缩放y轴???

我不认为自动缩放是问题所在,而是事件序列

您尝试在此行中“初始化”绘图:

function [h,w,y,graph] = lowpassFIR(sample)

%Calculates Finite Impulse Response low pass filter coefficient
%using the windowing methods as well

passEdge = 100;
StopbandAtt = 20;
passbandRip =.05;
transWidth = 10;
Fs = sample;





%Step One: select number of coefficients%
deltaF = transWidth/Fs;

%Normalize for each window


rectN = round(0.9/deltaF);

hannN = round(3.1/deltaF);
hammN = round(3.3/deltaF);
blackN = round(5.5/deltaF);

rectN = 1:rectN

%rectPos = round(rectN/2);
%rectNeg = round((rectPos*-1));


%For the Vector Array
%rect = rectNeg:rectPos;

deltaSum= passEdge + (transWidth/2);
deltaF2= deltaSum/Fs;

h=zeros(size(1:rectN(end)));
w=zeros(size(1:rectN(end)));
y=zeros(size(1:rectN(end)));
graph = plot(y)
for i = 1:rectN(end)

   %iterate through each value and plug into function in for loop
   %each output of the function will be stored into another array
    h(i) = 2*deltaF2*(sin(i*2*pi*deltaF2))/(2*i*pi*deltaF2);   
    w(i) = 0.5 + 0.5*cos(2*pi*i/rectN(end));
    y(i) = h(i)*w(i);
    graph(i) = y(i);
end
但是,在前一行中,您定义了

graph = plot(y);
因此,您看到的绘图将是一条位于
y=0
的直线。
graph
的值是,在本例中,您的
y=0

尝试设置绘图后,您将输入一个循环,并在每次迭代时向线句柄添加一个值(
graph(i)=y(i)
),但您不会绘制任何内容。如果在循环之后,您查看
y
graph
的值,您会看到新的值,但它们从未打印出来。
在这种情况下,我怀疑您是否需要一个循环,或许可以尝试以下方法:

y=zeros(size(1:rectN(end)));
请务必注意:
*


最后一点意见:您不应该使用
i
(或
j
)作为迭代器,因为它们在Matlab中也用作迭代器,如果您需要在代码中的某个地方使用,可能会产生问题

@user2514874如何删除循环?你使用我答案中的密码吗?
I = 1:rectN(end);
h = 2.*deltaF2.*(sin(I.*2.*pi.*deltaF2))./(2.*I.*pi.*deltaF2);   
w = 0.5 + 0.5.*cos(2.*pi.*I./rectN(end));
y = h.*w;
graph = plot(y);