フィルターのクリア

??? 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 Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by