Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.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
在for-loop matlab中实现findpeak_Matlab_Signal Processing - Fatal编程技术网

在for-loop matlab中实现findpeak

在for-loop matlab中实现findpeak,matlab,signal-processing,Matlab,Signal Processing,我已经编写了下面的代码来计算局部最大值及其在for循环中的位置,但是我得到了一个错误,即维度不匹配。我错过了什么 这是我的密码: for col = 1:3000; c1(:,col)=xc(2:end,col); % matrix xc is my matrix, it could be any random 2d matrix, and for each column i want to implement the findpeaks function

我已经编写了下面的代码来计算局部最大值及其在for循环中的位置,但是我得到了一个错误,即维度不匹配。我错过了什么

这是我的密码:

   for col = 1:3000;
         c1(:,col)=xc(2:end,col);
% matrix xc is my matrix, it could be any random 2d matrix, and for each column i want to implement the findpeaks function

         [cmax(:,col),locs(:,col)]=findpeaks(c1(:,col));

    end
FindPeak很可能为每个函数调用提供不同数量的检测峰值和位置。因为你试图分割成一个不参差不齐的矩阵,MATLAB不支持参差不齐的矩阵,你会得到一个维度不匹配

解决方案可能是使用单元阵列:

%// Declare cell arrays here
cmax = cell(3000,1);
locs = cell(3000,1);
for col = 1:3000;
     c1(:,col)=xc(2:end,col);
     %// Change
     [cmax{col},locs{col}]=findpeaks(c1(:,col));
end
但是,如果您不喜欢使用单元格数组,您可以创建一个NaN值矩阵,并且只填充每个结果检测到的最多峰值,并将其余条目保留为NaN。。。。比如说:

%// Declare cmax and locs to be an array of nans
cmax = nan(size(xc));
locs = nan(size(xc));
for col = 1:3000;
     c1(:,col)=xc(2:end,col);
     %// Change
     [c,l]=findpeaks(c1(:,col));
     %// Determine total number of peaks and locations
     N = numel(c);

     %// Populate each column up to this point
     cmax(1:N,:) = c;
     locs(1:N,:) = l;
end

给出完整的错误消息。它标识导致错误的命令。错误消息是:下标赋值维度不匹配。我理解为什么会出现错误,因为每列中的峰值数正在更改,所以我认为唯一的解决方案是使用cells@user_dsp-正确。考虑添加一个解释这个答案,或者删除你的问题,因为你已经解决了你的问题…或者,我可以补充一个答案: