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)))
答案 0 :(得分:2)
这个问题似乎是不同大写iPeaksK
和iPeasksk
的混合,并且使用了让Matlab认为iPeaksK是实际功能的结尾。我建议选择两个大写中的一个并修复所有其他大写。