我对Matlab并不陌生,但是在这种情况下,我遇到了一个以前没有遇到过的非常奇怪的错误。我试图制作我的代码的简化版本来演示我遇到的错误。基本上,我有索引错误,但正在访问的索引是一个正整数。
我想知道它是否与索引号的格式有关。无论如何,任何帮助或建议将不胜感激。
t=(0:0.00001:2*pi);
Cir(1,1:length(t)) = 0;
Cir(2,1:length(t)) = 0;
Cir(3,1:length(t)) = 0;
D0(1:length(t)) = 0;
% Search for the first minimum
[min1D0,t1Found] = min(abs(D0(1:length(t)/2)));
% Search for the second minimum
[min2D0,t2Found] = min(abs(D0(length(t)/2:length(t))));
t2Found = t2Found + length(t)./2; % Add tIndex/2 to correct the index
C1 = [Cir(1,t1Found),Cir(2,t1Found),Cir(3,t1Found)];
C2 = [Cir(1,t2Found),Cir(2,t2Found),Cir(3,t2Found)];
输出是:
Warning: Integer operands are required for colon operator when used as index
Warning: Integer operands are required for colon operator when used as index
??? Attempted to access Cir(1,314161); index must be a positive integer or logical.
注意:我使用的是 R2009b。