• Register
0 votes
76 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);

    MyCointMatrix= zeros(MyNofStocks);

    [rows, cols] = find(MyCointMatrix);

    MyCointPairs = [rows, cols];

    **mycf= (MyCointPairs(:,1)-MyCointPairs(:,2))==0;**

    MyCointPairs(mycf,:) = [];

    if(isempty(MyCointPairs))

        warning('No Cointegrated Pairs Found Here')

        return

    end

end

And the problem generally occurs at below line:

mycf= (MyCointPairs(:,1)-MyCointPairs(:,2))==0;

Saying that the "Subscript indices must either be real positive integers or logicals." And the input variable "MyPriceMat" is the price matrix of 60x10, and "MySymbols" is the 10x1 string.

One more doubt from my side what are "Subscript indices"?

6 5 3
7,540 points

Please log in or register to answer this question.

2 Answers

0 votes

Solution :

"Subscript indices must either be real positive integers or logicals." This means the index that you want to reference does not really exist. Most probably it means MyCointPairs(:,2) does not really exist.

So my suggestion to you is to put the break point in the following line MyCointPairs = [rows, cols]; and observe the size of your MyCointPairs matrix. and also try to see whether your second column really exist or not.

Hope this helps you in clearing all your doubt and resolves your errors.

9 7 4
38,600 points
0 votes

This error occurs when the user attempts to index an array using the indices that are not positive integers or logical values.

Solutions:

Here are some common solutions for this error;

Double-check that your indices are positive integers, Indices in MATLAB cannot be p and by default start with 1.

Logical indexing:

If you are using the logical indexing to index the array, then make sure that your index array is of type “logical” and not a “double” array of 1s and 0s. You can convert the “double” array to a logical array before attempting to use logical indexing.

Example:

A = [1 2 3 4; 5 6 7 8];

ind_double = [0 1 0 1; 0 1 0 1];

ind_logical = logical(ind_double);

A(ind_logical)

For index array ‘ind’ you can check its data type by using the whos function;

whos ind

Floating-point arithmetic:

If you are using the floating-point arithmetic to compute the index array, then the array values may not be an integer. The “round” function is useful when you know you have an index value that is nearly integer index according to your needs.

Example:

A = [1 2 3 4; 5 6 7 8];

ind_float = 2.00001;

ind_int = round(ind_float);

A(ind_float)

Below is the method to check if an index array “ind” contains exact integer values. This command returns a logical array where 1 indicates the index value is an exact integer and o indicated it is not.

ind == round(ind)

 

11 5 2
3,890 points

Related questions

0 votes
1 answer 134 views
134 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.
asked Jan 28, 2020 jwilliam 3.9k points
0 votes
1 answer 3 views
3 views
Problem: Hi ! I am facing this issue can any body help please?
asked Mar 18 PkGuy 13.1k points
0 votes
1 answer 2 views
2 views
Problem: I'm currently running my code, and found an annoying problem that I really haven't got any idea to solve. The function that I'm working out is as follows; function out = CointPairs(PriceMat, Symbols) out=[]; NofStocks = size(PriceMat, 2); CointMatrix= ... 60x10, and "Symbols" is 10x1 string. One more question :) what's exactly meant by "subscript indices"? MUCH appreciated in advance xx
asked 6 days ago nabin shrestha 2.6k points
0 votes
2 answers 741 views
741 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 33 views
33 views
Problem : Matlab Error : Z must be a matrix, not a scalar or vector.
asked Feb 25 Shovo210 13.2k points
0 votes
1 answer 5 views
5 views
Problem: I am stuck with this ... Please help me that how to deal with this error? operands to the and && operators must be convertible to logical scalar values. matlab
asked Mar 23 Ifra 24.4k points
0 votes
1 answer 2 views
2 views
Problem: Who can give me the solution of this topic I have got as a queston that indices must be integers or slices not float?
asked 3 days ago ashik 10.7k points
0 votes
1 answer 2 views
2 views
Problem: Any ideas on what I need to fix this?list indices must be integers or slices, not float
asked 3 days ago ashik 10.7k points
0 votes
1 answer 12 views
12 views
Problem: I am trying to pull data from a database and assign them to different lists. This specific error is giving me a lot of trouble "TypeError: tuple indices must be integers, not str" I tried converting it to float and etc but with no success. Any help would be appreciated! Thanks people!
asked Mar 16 ummesalma 22.9k points