Matlab下标索引错误
Matlab subscript indices error
请帮助我。每当我将 0 值放在我的 "data" 上时,我总是得到一个下标索引必须是正整数或逻辑错误我如何才能摆脱它,我需要在那个上有一个零。每当电压 (1,0) = 1 为零时。但我无法通过。
Voltage = [0 1 1 3 4 1; 1 0 5 4 5 3; 6 4 0 4 5 7; 9 3 4 0 6 4; 7 8 5 6 0 7; 4 5 6 7 3 0];
data =[0 2 3 4; 5 6 7 8; 2 3 4 5; 4 5 6 7; 3 4 5 6; 1 3 5 7; 1 2 3 4; 3 4 5 6];
Vm = data(:,1);
Vn = data(:,2);
R = data(:,3);``
X1 = data(:,4);
sz=max(Vn)
y=1:sz
for Vm=data(:,1)
if Vm==0
Voltage(y,Vm)=1
Voltage(y,Vm)=logical(Voltage(y,Vm));
Current = Voltage(y,Vm)-Voltage(y,Vn);
else Vm >= 1
Current = Voltage(y,Vm)-Voltage(y,Vn);
end
end
您正在尝试使用 y
在 Voltage
矩阵的 else 语句中引用一个值,但 y
不是整数,而是数组(或一维矩阵)。如果显示 y
,您会看到它是 1 2 3 4 5 6
。违规代码有几段,其中一段是:
else Vm >= 1
disp(y) # `y` is not an integer and therefore not a valid index.
Current = Voltage(y,Vm)-Voltage(y,Vn);
要修复它,决定 y
应该是静态的还是在循环中改变。
如果您需要进一步的解释,请告诉我。
请帮助我。每当我将 0 值放在我的 "data" 上时,我总是得到一个下标索引必须是正整数或逻辑错误我如何才能摆脱它,我需要在那个上有一个零。每当电压 (1,0) = 1 为零时。但我无法通过。
Voltage = [0 1 1 3 4 1; 1 0 5 4 5 3; 6 4 0 4 5 7; 9 3 4 0 6 4; 7 8 5 6 0 7; 4 5 6 7 3 0];
data =[0 2 3 4; 5 6 7 8; 2 3 4 5; 4 5 6 7; 3 4 5 6; 1 3 5 7; 1 2 3 4; 3 4 5 6];
Vm = data(:,1);
Vn = data(:,2);
R = data(:,3);``
X1 = data(:,4);
sz=max(Vn)
y=1:sz
for Vm=data(:,1)
if Vm==0
Voltage(y,Vm)=1
Voltage(y,Vm)=logical(Voltage(y,Vm));
Current = Voltage(y,Vm)-Voltage(y,Vn);
else Vm >= 1
Current = Voltage(y,Vm)-Voltage(y,Vn);
end
end
您正在尝试使用 y
在 Voltage
矩阵的 else 语句中引用一个值,但 y
不是整数,而是数组(或一维矩阵)。如果显示 y
,您会看到它是 1 2 3 4 5 6
。违规代码有几段,其中一段是:
else Vm >= 1
disp(y) # `y` is not an integer and therefore not a valid index.
Current = Voltage(y,Vm)-Voltage(y,Vn);
要修复它,决定 y
应该是静态的还是在循环中改变。
如果您需要进一步的解释,请告诉我。