Index is out of range for deletion ???
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Image Analyst
el 28 de Mayo de 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.
Respuestas (1)
dpb
el 28 de Mayo de 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 comentarios
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!