当我运行此代码时:
clc, clear all
%% loading data
% allowed data type xy.txt, where x is a letter (j) nad y is number (i)
for j=0:3
switch j
case 0
variable='i';
case 1
variable='u';
case 2
variable='p';
case 3
variable='q';
end
for i=0:15
name = strcat(variable, int2str(i), '.txt')
fid=fopen(name,'r');
data=textscan(fid,'%*s%*s%s%s%s%*s','HeaderLines',10,'CollectOutput',1);
fclose(fid);
data=strrep(data{1},',','.');
data=cellfun(@str2num, data);
m.(variable){i+1}=data;
end
end
%% calculations
phase1 = 1424;
phase2 = phase1*2;
phase3 = phase2*2;
% voltage
u_na=m.u{2}(1:phase1);
u_nb=m.u{2}(phase1+1:phase2);
u_nc=m.u{2}(phase2+1:end);
% *voltage harmonic
% current
i_na=m.i{2}(1:phase1);
i_nb=m.i{2}(phase1+1:phase2);
i_nc=m.i{2}(phase2+1:end);
i_ha(1:phase1)=0;
i_hb(1:phase1)=0;
i_hc(1:phase1)=0;
for k=1:15
if k==2
break;
end
i_ha = i_ha + m.i{k}(1:phase1);
i_hb = i_hb + m.i{k}(phase1+1:phase2);
i_hc = i_hc + m.i{k}(phase2:end); %this line cause error
end
循环中的最后一行,导致错误:
这是可变尺寸:
有人想过问题出在哪里?这些行:
i_ha = i_ha + m.i{k}(1:phase1);
i_hb = i_hb + m.i{k}(phase1+1:phase2);
i_hc = i_hc + m.i{k}(phase2:end);
看起来很简陋,但只是最后一个问题。我尝试将end更改为phase1 * 3,但这并没有帮助。
答案 0 :(得分:1)
i_hc = i_hc + m.i{k}(phase2+1:end);
我认为你在代码中犯了一个错误..只需相应地改变它。