MYSTERY matlab Error - Index exceeds matrix dimensions - can't track it!

1 回表示 (過去 30 日間)
void22
void22 2018 年 6 月 21 日
編集済み: per isakson 2018 年 6 月 21 日
hi everyone , i have this silly error but i'm not able to fix it , since i don't see any index exceeding the matrix dimensions .
function [ Hclean,Bclean , EnergyDissipation ,InnerMagnetization ] = BHavg( B,H )
for t=1:size(H,1)
InnerB=[];
InnerBnegative=[];
ZeroIndexTemp = find(abs(H(t,:))-0.03<0.005);
for p =1:size(ZeroIndexTemp,2)
if B(t,ZeroIndexTemp(p))>0
InnerB=[InnerB,B(t,ZeroIndexTemp(p))];
else
InnerBnegative=[InnerBnegative ,B(t,ZeroIndexTemp(p))];
end
end
InnerMagnetization(t) = mean(InnerB);
ErrorManetization(t) = abs(InnerMagnetization(t) + mean(InnerBnegative));
ZeroIndex =[];
for i =1:size(ZeroIndexTemp,2)-1
if ZeroIndexTemp(i+1)-ZeroIndexTemp(i)>10
ZeroIndex=[ZeroIndex,ZeroIndexTemp(i)];
end
end
loopHTemp={};
loopH=[];
loopB=[];
loopBTemp={};
for j = 1:(size(ZeroIndex,2)-2)/2
loopHTemp{j}=H(ZeroIndex(j*2):ZeroIndex(j*2+2));
loopBTemp{j}=B(ZeroIndex(j*2):ZeroIndex(j*2+2));
end
VsizeCount =[];
for k=1:size(loopHTemp,2)
VsizeCount=[VsizeCount,size(loopHTemp{k},2)];
end
minListSize = min(VsizeCount);
for m=1:size(loopHTemp,2)
loopHTemp{m}(minListSize+1:end)=[];
loopH(m,:)=loopHTemp{m};
loopBTemp{m}(minListSize+1:end)=[];
loopB(m,:)=loopBTemp{m};
end
A=[];
B=[];
for y=1:size(loopH,1)
A=[A;loopH(y,:)];
B=[B;loopB(y,:)];
end
if size(loopH,1)>1
Hclean(t,:) = mean(A);
Bclean(t,:) = mean(B);
else
Hclean(t,:) = loopH(:,i);
Bclean(t,:) = loopB(:,i);
end
EnergyDissipation(t) = polyarea(Hclean(t,:),Bclean(t,:));
if EnergyDissipation(t) >5
figure
fill(Hclean(t,:),Bclean(t,:),'b')
end
end
end
i added the entire code since maybe it's not related to the error message matlab shows me , but this is what it shows
Index exceeds matrix dimensions.
Error in BHavg (line 8)
if B(t,ZeroIndexTemp(p))>0
please help ! (:
  6 件のコメント
void22
void22 2018 年 6 月 21 日
B and H are 100x2500 matrixes
per isakson
per isakson 2018 年 6 月 21 日
"i guessed correctly" You shouldn't guess, but consult the documentation!

サインインしてコメントする。

回答 (1 件)

per isakson
per isakson 2018 年 6 月 21 日
編集済み: per isakson 2018 年 6 月 21 日
  • B is overwritten at line 43 and the following loop.
  • In the second and the following iterations of the outer loop, t>=2, the size of B may be so small that B(t,ZeroIndexTemp(p)) causes the error. "Index exceeds matrix dimensions."

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by