Filter löschen
Filter löschen

??? Matrix index is out of range for deletion...

121 Ansichten (letzte 30 Tage)
Mamali
Mamali am 23 Mai 2014
Kommentiert: dpb am 25 Mai 2014
[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 Kommentare
Sara
Sara am 23 Mai 2014
What is the size of path?
Mamali
Mamali am 24 Mai 2014
Bearbeitet: Mamali am 24 Mai 2014
The Size is a 3 dimensional matrix changing size on every iteration happening in an other loop. The third dimension of size is the same as finalCost1DMatrix. The third dimension of finalCost1DMatrix is my final answer which needs to be minimised that's y I'm deleting if the 9th element of path is not zero( I want hops in routes to be less than 9)

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

dpb
dpb am 24 Mai 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 Kommentare
dpb
dpb am 24 Mai 2014
Bearbeitet: dpb am 24 Mai 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
dpb am 25 Mai 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?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

dpb
dpb am 23 Mai 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.

Mamali
Mamali am 24 Mai 2014
Bearbeitet: Mamali am 24 Mai 2014
Thanks for your answer dpb, path is a three dimensional array aligned with finalCost1DMatrix( they have a changing size in the 3rd dimension on every iteration happening in another loop )Can you please elaborate further...

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by