??? Matrix index is out of range for deletion...
121 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
[finalLinkCost1DMatrix, path, corelation] = getSetOfPlanes(topology,realCapacityTopology,costTopology,AR,GW,X(x));
path1=path;
finalLinkCost1DMatrix1=finalLinkCost1DMatrix;
for k=1:size(finalLinkCost1DMatrix,3)
for f=1:6
if path(f,8,k)~=0
path1(:,:,k)=[];
finalLinkCost1DMatrix(:,:,k)=[];
break;
else
continue;
end
end
end
I get
??? Matrix index is out of range for deletion.
Error in ==> topo at 76 path1(:,:,k)=[]; Can anyone help me with this. with thanks
2 comentarios
Respuesta aceptada
dpb
el 24 de Mayo de 2014
Trivial example implemented two ways--
a) your case (from beginning)...
X=rand(10,1);
for i=1:length(X)
if(X(i)<0.5)
X(i)=[];
end
end
b) correctly (the first alternative given earlier)...
X=rand(10,1);
for i=length(X):-1:1
if(X(i)<0.5)
X(i)=[];
end
end
It's same thing excepting for a 1D array instead of 3D and one small array so you can use debugger if need to to understand the difference.
3 comentarios
dpb
el 24 de Mayo de 2014
Editada: dpb
el 24 de Mayo de 2014
path1(:,:,k,g)=[];
'A null assignment can have only one non-colon index.'
There really is no solution to this -- k,g are single indices so the reference (:,:,g,k) is a single point in the 4D array. You can't create "holes" in a ND array; it would be "ragged" array of a variable number of points in one or more of those dimensions.
You can eliminate a complete plane as in your prior case or along any other dimension that leaves a resulting regular array, but not individual points scattered around willy-nilly as the above logic does.
You could store a NaN instead as an indicator or remove a slice the full dimension at the location, but not the individual point.
dpb
el 25 de Mayo de 2014
I looked at that (before you deleted it, apparently) and couldn't make heads nor tails of it, either, sorry.
Can you make up a (tiny) sample data set that could illustrate the inputs and desired results and post that as well?
Más respuestas (2)
dpb
el 23 de Mayo de 2014
for k=1:size(finalLinkCost1DMatrix,3)
for f=1:6
if path(f,8,k)~=0
path1(:,:,k)=[];
finalLinkCost1DMatrix(:,:,k)=[];
...
First problem is you've not shown definition for path so can't tell about the subject error line precisely, but presuming it also is commensurate with k, you have implemented a classic "woops" case.
You started from k=1 working to the end of the total number of planes in your working arrays and delete an element, thus shortening the remaining array. In your case the element is a plane, it's common error in processing strings or 1D vectors as well.
You need to either
a) Reverse the processing on k to remove the LAST plane(s) first, or,
b) Make a secondary array of those planes which need removing and after the list is populated, do a global change.
0 comentarios
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices 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!