• Register
0 votes
76 views

Problem :

The below error occurs quite frequently to me:

“Subscript indices must either be real positive integers or logical”

I want to have a general solution for dealing with above problem.

7 5 2
3,870 points

1 Answer

0 votes

Solution :

It is very important to know the powerful yet very intuitive feature of the matrix indexing in Matlab. So how indexing actually works and what is the valid index would help avoid above error in a first place by using the valid indices.

At its very core, given the array A of length n, there are two ways to index it.

1. Linear indexing: With a subset of integers from 1 : n ,0 is not allowed, as the Matlab arrays are 1-based, unless you use a method below. For a higher-dimensional arrays, multiple subscripts are the internally converted into a linear index, although in the efficient and transparent manner.

2. Logical indexing: When you use the n-length array of 0s and 1s, to just pick those elements where the indexing is true. In this case, the unique(index) must have only 0 and 1.

So the valid indexing array into another array with the n number of elements can be:

1. Entirely logical of a same size, or

2. Linear with a subsets of integers from 1:n

So invalid indexing error always occurs when you try to mix the two types of indexing: one or more zeros occur in the linearly indexing array, or you just mix 0s and 1s with anything other than 0s and 1s.

9 7 4
38,600 points

Related questions

0 votes
2 answers 56 views
56 views
Problem : I am currently trying to run my code but found the really annoying problem which I am unable to solve. The function that I am currently working out is as below; function myout = MyCointPairs(MyPriceMat, MySymbols) myout=[]; MyNofStocks = size(MyPriceMat, 2); ... is the price matrix of 60x10, and "MySymbols" is the 10x1 string. One more doubt from my side what are "Subscript indices"?
asked Dec 25, 2019 alecxe 7.5k points
0 votes
2 answers 263 views
263 views
Problem : I am facing following error message: Index in position 1 is invalid. Array indices must be positive integers or logical values. My code is as follows: clc; close all; clear; PD=phantom('Modified Shepp-Logan'); padimage = [2,2]; PD= padarray(PD, ... : Index in position 1 is invalid. Array indices must be positive integers or logical values. Can anybody tell me why the issue is here?
asked Nov 24, 2019 alecxe 7.5k points
0 votes
1 answer 10 views
1 vote
1 answer 50 views
50 views
Problem : I am very new to Programming. Currently I am trying to learn the Python. I am trying to slice my list (myplateau) in the several list (L[i]) but because of some unknown reasons to me I am facing the below error message: File "C:\Users\Martin\Skycraper ... ]     L.append(myitem)     i += 1 I am very confused about above error. Please help me in fixing above mentioned python related error.
asked May 13 Martin K 6.6k points