简体   繁体   English

用Matlab编码将向量实现到矩阵

[英]Implementing vectors to a matrix with Matlab coding

Hey I am using a FIR filter on a signal. 嘿,我在信号上使用FIR滤波器。 And I want to make the HF variable a matrix that contains the values of L in the variable hf. 我想使HF变量成为一个包含变量hf中的L值的矩阵。 Like this: 像这样:

HF = [hf1, hf2, hf3, hf4, hf5]; HF = [hf1,hf2,hf3,hf4,hf5];

So that I can use the matrix HF in a subplot there I can get a view over the plots of each hf vector. 这样我就可以在子图中使用矩阵HF,在那里可以查看每个hf向量的图。

As you can see I got a tip of writing HF = [HF, hf]; 如您所见,我得到了写作HF = [HF, hf];的技巧HF = [HF, hf]; that should implement the vector of hf to the matrix HF. 应该将hf的向量实现到矩阵HF。 But I can't get it to work. 但是我无法正常工作。

Here is the code that I am using: 这是我正在使用的代码:

w0 = 9*pi/80;
for L = [5,10,50,100,1000]
   n = 1:L;
   dum = (sin(w0.*n))./(pi.*n);
   h = [fliplr(dum),w0/pi,dum];
   % stem(h);

   hfft = fft([h,zeros(1,(4096-length(h)))]);
   hf = log10(hfft.*conj(hfft)/(Fs*7)/2);

   HF = [HF,hf];
   %figure(7)
   %plot(hf(1:2048));
   %pause
end

r = 3;
c = 2;
Plotnb = 1;
for i=1:r
    for j=1:c
        subplot(r,c,Plotnb)
        plot(HF(:,Plotnb)); % Picks out the right column.
        Plotnb=Plotnb+1;
    end
end

% y2=conv(x,h);
% sound(y2,Fs);

Any tips would be much appreciated! 任何提示将不胜感激!

Thanks for the help 谢谢您的帮助
Daniel 丹尼尔

Almost there, you just need to add 差不多了,您只需要添加

HF = [];

before entering the for loop. 在进入for循环之前。 If you don't do that, the program fails on HF = [HF,hf]; 如果不这样做,则程序在HF = [HF,hf];失败HF = [HF,hf]; because you are trying to concatenate hf with something that does not exist yet. 因为您正在尝试将hf与尚不存在的东西连接起来。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM