我试图从Matlab中生成的m * n数据表中选择一个特定的数组。它显示索引超过矩阵维度的错误。 有关详细信息,请查看以下代码:
t_res = 0.2;
c_angle = 360/30;
iact = 0.1;
V = 12;
p = 1;
for p=1:length(p),
for p=1:5,
Time = p*t_res;
Angle = Time*c_angle/2;
if (p == 1)
delt_i = 0;
else
delt_i = 0.5* t_res* V /L_obt;
end
iact = iact+delt_i;
[~, ~, raw] = xlsread('F:\Pradeep\Matlab\data1.xlsx','Sheet3','A2:D11');
data = reshape([raw{:}],size(raw));
Current = data(:,1);
Angle1 = data(:,2);
Torque = data(:,3);
Fluxlinkage = data(:,4);
F = scatteredInterpolant(Current,Angle1,Fluxlinkage);
Fluxlinkage = F(iact,Angle);
L_obt = Fluxlinkage/iact;
F = scatteredInterpolant(Current,Angle1,Torque);
Torque = F(iact,Angle);
Table = [p' Time' Angle' iact' delt_i' abs(Torque)' Fluxlinkage' L_obt'];
fprintf('%d\t\t %f\t\t %f\t\t %f\t\t %f\t\t %f\t\t %f\t\t %f\n', Table');
end
p=p+1;
Table(3,5);
end
答案 0 :(得分:1)
首先,在第11行你说:
delt_i = 0.5* t_res* V /L_obt;
但L_obt
似乎没有被定义。
然后,第38行的说明有问题:
Table(3,5);
由于Table
是一维数组(一行包含8个值),因此您只需要一个1到8之间的数字,例如Table(3)
或Table(5)
。在二维数组的情况下,Table(3,5)
意味着您需要第3行和第5列中的值。
答案 1 :(得分:1)
以下是您的代码的重组版本。我把那些不需要进入循环的东西移出了它。并对你真正想要做的事做了一些假设。有关更改的说明,请参阅下面的注释。注意:我无法对此进行测试,因为我没有您的电子表格,但至少应该让您更接近。
t_res = 0.2;
c_angle = 360/30;
iact = 0.1;
V = 12;
%p = 1; %This does nothing since your iterate over p in the loop
%These things don't depend n "p" so don't put them in the loop
[~, ~, raw] = xlsread('F:\Pradeep\Matlab\data1.xlsx','Sheet3','A2:D11');
data = reshape([raw{:}],size(raw));
Current = data(:,1);
Angle1 = data(:,2);
Torque = data(:,3);
Fluxlinkage = data(:,4);
F1 = scatteredInterpolant(Current,Angle1,Fluxlinkage);
F2 = scatteredInterpolant(Current,Angle1,Torque);
%I assume you want to build your var "Table" in the loop ... not to be
%confused with an actaul Matlab type "table" ... so pre-allocate
Table = zeros(5,8);
for p=1:5,
Time = p*t_res;
Angle = Time*c_angle/2;
if (p == 1)
delt_i = 0;
else
delt_i = 0.5* t_res* V /L_obt;
end
iact = iact+delt_i;
Fluxlinkage = F1(iact,Angle);
L_obt = Fluxlinkage/iact;
Torque = F2(iact,Angle);
%You were just overwritning the same row again and again ... so create
%a new row for each results.
Table(p,:) = [p Time Angle iact delt_i abs(Torque) Fluxlinkage L_obt];
%Print the new row.
fprintf('%d\t\t %f\t\t %f\t\t %f\t\t %f\t\t %f\t\t %f\t\t %f\n', Table(p,:));
end
%Not sure what this is for ... since the output is surpressed by the
%semi-colon ???
Table(3,5);