limiting columns of a matrix
1 view (last 30 days)
Show older comments
I'm trying to have limitation over the columns of a matrix. The limits are set automatically during running the code and the values of limits are indices of columns. Some times the value of the limits are [] and when I run the following code I get this error:Index exceeds array bounds.
here is the code:NewPrime_CO=NewPrime_CO(: , [1:limit1(1)-1 limit1(end)+1:limit2(1) limit2(end)+1:end]);
I can't find out what to do to solve it. Thanks in advance
2 Comments
Accepted Answer
Bob Thompson
on 1 Feb 2019
Edited: Bob Thompson
on 1 Feb 2019
The reason you're getting that error is because you cannot call the index of an empty array. If limit1 is (1x0) double and you attempt to call limit1(1) you will receive this error. Although the variable technically has a row dimension, there is no actual element to call, so calling any element exceeds the matrix dimensions. I would suggest working around this by concatonating all of your limits together and entering them as one array.
limits = [limit1 limit2];
NewPrime_CO(:,limits) = [];
0 Comments
More Answers (0)
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!