-2

matlab给了我这个错误

???错误:文件:Untitled2.m 行:70 列:19 (此处发布的代码的最后一行) 构造“iPeaksK(...end...)”在此上下文中不明确,因为无法确定“iPeaksK”可以是变量的名称,也可以是函数的名称。要使其成为变量,请分配给它;要让它在执行时成为一个函数,请将“end”替换为对所需数组的 LENGTH、SIZE 或 NUMEL 的调用。

你能告诉我错误在哪里吗?非常感谢oyu。

  %knee
  xk = excel(:,13);
  yk = excel(:,14);
  zk = excel(:,15);
  [peaksk, iPeaksk] = findpeaks(-yk); 
  peaksk=-peaksk;
  wantedPeaksk = peaksk < ((max(yk) + min(yk))/2); %returning 0 or 1
  peaksk = peaksk(wantedPeaksk); %now we only have the good peaks/indexes
  iPeaksk = iPeaksk(wantedPeaksk);
  figure;subplot(221); plot(iPeaksk,peaksk,'*');hold on;plot(yk)
  IPEAKSLENGTHK = zeros(1, length(iPeaksk) - 1);
  for i = 1 : length(iPeaksk) - 1
      iPeaks1k = iPeaksk(i);
      iPeaks2k = iPeaksk(i + 1) - 1;
      IPEAKSLENGTHK(i) = length(iPeaks1k:iPeaks2k);
  end

  interpxsumk = zeros(1, 100);
  interpysumk = zeros(1, 100);
  interpzsumk = zeros(1, 100);
  for i = 1 : length(iPeaksk) - 1
      iPeaks1k = iPeaksk(i);
      iPeaks2k = iPeaksk(i + 1) - 1;

      %data between each pair of peaks - not interpolated
      xPeaks12k = xk(iPeaks1k:iPeaks2k);
      yPeaks12k = yk(iPeaks1k:iPeaks2k);
      zPeaks12k = zk(iPeaks1k:iPeaks2k);

      subplot(2,2,2)
      plot3(xPeaks12k, zPeaks12k, yPeaks12k, 'r*')
      title('final data (black) // interpolated data (green) // selected data (red)', 'FontSize', fontSize);
      xlabel('x', 'FontSize', fontSize);
      ylabel('z', 'FontSize', fontSize);
      zlabel('y', 'FontSize', fontSize);
      axis equal;
      grid on;
      hold on

      %interpolate each cycle to take the average curve
    originalIndexesk = 1 : length(xPeaks12k); % same as   =linspace(1, length(xPeaks12), length(xPeaks12)) 
        interpIndexesk = linspace(1, length(xPeaks12k), 100); %creating 100 indexes from 1 to length(xPeaks12)
      interpxk = interp1(originalIndexesk, xPeaks12k, interpIndexesk, 'spline'); %find new values=interpolate->spline_best option // http://www.mathworks.com/help/matlab/ref/interp1.html
      interpyk = interp1(originalIndexesk, yPeaks12k, interpIndexesk, 'spline');
      interpzk = interp1(originalIndexesk, zPeaks12k, interpIndexesk, 'spline');
    plot3(interpxk, interpzk, interpyk, 'g*'); %cycles interpolated
    interpxsumk = interpxsumk + interpxk;
        interpysumk = interpysumk + interpyk;
      interpzsumk = interpzsumk + interpzk;
  end
  newxk = interpxsumk / (length(iPeaksk) - 1); %average x -1inicial-1final-1
  newyk = interpysumk / (length(iPeaksk) - 1);
  newzk = interpzsumk / (length(iPeaksk) - 1);

  plot3([newxk(end) newxk], [newzk(end) newzk], [newyk(end) newyk], 'k-', 'LineWidth', 5); %close to plot

  %param
  zzwalkingtimeK=(t(iPeaksK(end))-t(iPeaksK(1)))
4

1 回答 1

2

问题似乎是不同大小写的混合,iPeaksK并且iPeaskskend 的使用使 Matlab 误以为 iPeaksK 是一个实际函数。我建议解决两个大写之一并修复所有其他大写。

于 2012-12-02T11:10:00.690 回答