【问题标题】:Subscripted assignment dimension mismatch - Periodogram MATLAB下标赋值维度不匹配 - Periodogram MATLAB
【发布时间】:2017-01-31 07:01:41
【问题描述】:

我在MATLAB上写了如下代码:

N = [64 128 256 512];
NumOfRuns = 50;   
PerLength = 2048;  
freq = 0:2/(PerLength-1):2;
for m=1:length(N)
    Px = zeros(NumOfRuns,PerLength);
    for i=1:NumOfRuns
        x = randn(1,N(m));
        Px(:,i) = periodogram(x);
    end
end

当我在 MATLAB 上运行此代码时,它给出了错误:

下标分配维度不匹配。 示例 13 中的错误(第 10 行)Px(:,I)=periodogram(x)。

【问题讨论】:

标签: matlab


【解决方案1】:

代码注释:

N = [64 128 256 512];
NumOfRuns = 50;   
PerLength = 2048; 

% freq = 0:2/(PerLength-1):2; % you are not using freq

% You are looping from 1:4, defining Px each time, not storing Px outside of the loop. 
% After this loop, Px will just be in its 4th state. 
for m = 1:length(N)

    Px = zeros(NumOfRuns,PerLength);

    for i = 1:NumOfRuns 

        x = randn(1,N(m));
        Px(:,i) = periodogram(x);

    end

end

周期图:

您假设periodogram 返回的元素数量与输入给它的元素数量相同。一个简单的测试就会告诉你这不是真的!

a = periodogram([1, 2]);
numel(a)
% >> ans = 129

在此处阅读文档:

https://uk.mathworks.com/help/signal/ref/periodogram.html

离散傅里叶变换 (DFT) 中的点数 nfft 最大为 256 或大于信号长度的 2 的次幂

所以上面,1292^7 = 128 相关

尝试使用pxx = periodogram(x,window,nfft)

【讨论】:

  • 感谢您的帮助。它适用于单个情节。但我想要以下内容: 1. 存储 PX 并获得 50 个集成图。我把代码放在这里用于绘制合奏,因为我可以接受。
猜你喜欢
  • 2013-05-30
  • 2013-07-03
  • 1970-01-01
  • 2023-04-05
  • 1970-01-01
  • 1970-01-01
  • 2015-04-11
  • 1970-01-01
  • 2017-01-26
相关资源
最近更新 更多