Index is out of range for deletion ???
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hello guys. I get an error when I run the code pasted below.
error:
Matrix index is out of range for deletion.
Error in topo (line 194) path1(:,:,g)=[];
HERE IS THE CODE:
[finalLinkCost1DMatrix, path, corelation] = getSetOfPlanes(topology,realCapacityTopology,costTopology,AR,GW,X(x));
path1=path; % path(6,19,finalLinkCost1DMatrix)
for g = size(finalLinkCost1DMatrix,3):-1:1
for f = 1:size(AR,2) % 1:6
for h=1:size(finalLinkCost1DMatrix,2) % 1:19
if path(f,h,g)~=0
path1(:,:,g)=[];
finalLinkCost1DMatrix(:,:,g)=[];
HopCountLimitRequired=CheckHopNumber(finalLinkCost1DMatrix)
if HopCountLimitRequired==1
HopCount=h;
break
else
continue
end
end
end
end
end
size(finalLinkCost1DMatrix,3) is my final answer.
HopCountLimitRequired=CheckHopNumber(finalLinkCost1DMatrix) is a BOOL function that checks whether size(finalLinkCost1DMatrix,3) meets certain criteria(e.g <6 && >3)
I would really appreciate if you can help me correct my approach.
3 Commenti
Image Analyst
il 28 Mag 2014
One other tip. Before you paste in here, highlight your code in MATLAB, then type Ctrl-i to properly indent your code . Then paste in here, highlight, then and only then click the {}Code button.
Risposte (1)
dpb
il 28 Mag 2014
for g = size(finalLinkCost1DMatrix,3):-1:1
for f = 1:size(AR,2) % 1:6
for h=1:size(finalLinkCost1DMatrix,2) % 1:19
if path(f,h,g)~=0
path1(:,:,g)=[];
finalLinkCost1DMatrix(:,:,g)=[];
...
As soon as you remove the plane g, anything else is invalid and there's no point in continuing in the loops on f and h (and, in fact, it's going to error if there's a second point in the path array as you've already discovered).
BTW, path is a Matlab m-file function; not a good idea to alias functions; I'd suggest finding a new name for it.
Since it appears that you're testing every value in each plane, it would be far more efficient and remove a lot of your looping issues of leaving a triply-nested loop if you wrote
for g = size(finalLinkCost1DMatrix,3):-1:1
if any(path(:,:,g)
path1(:,:,g)=[];
finalLinkCost1DMatrix(:,:,g)=[];
% other stuff needed for this plane goes here
...
continue
end
end
0 Commenti
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!