필터 지우기
필터 지우기

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

조회 수: 121 (최근 30일)
Mamali
Mamali 2014년 5월 23일
댓글: dpb 2014년 5월 25일
[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
Sara
Sara 2014년 5월 23일
What is the size of path?
Mamali
Mamali 2014년 5월 24일
편집: Mamali 2014년 5월 24일
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)

댓글을 달려면 로그인하십시오.

채택된 답변

dpb
dpb 2014년 5월 24일
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
dpb
dpb 2014년 5월 24일
편집: dpb 2014년 5월 24일
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 2014년 5월 25일
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?

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

dpb
dpb 2014년 5월 23일
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 2014년 5월 24일
편집: Mamali 2014년 5월 24일
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...

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by