. Advertisement .
..3..
. Advertisement .
..4..
Here is the program I run:
function out = CointPairs(PriceMat, Symbols)
out=[];
NofStocks = size(PriceMat, 2);
CointMatrix= zeros(NofStocks);
[rows, cols] = find(CointMatrix);
CointPairs = [rows, cols];
**cf= (CointPairs(:,1)-CointPairs(:,2))==0;**
CointPairs(cf,:) = [];
if(isempty(CointPairs))
warning('No Cointegrated Pairs Found')
return
end
end
cf= (CointPairs(:,1)-CointPairs(:,2))==0;
After I run, it returns an error:
[Err] ERROR:
Subscript indices must either be real positive integers or logicals
Does anyone have any suggestions for the problem below: subscript indices must either be real positive integers or logicals. matlab in the matlab. How to correct it?
The cause:
After researching your problem for hours, I found that you had tried to reference the
CointPairs
variable, but it didn’t exist. This is due to when you ranfind
, there was not an entry that was equal 1 or different with 0 in your CointMatrix. It can be seen from that you attempted to access your matrix by using invalid inputs, so the error occured.Solution:
You are only allowed to use the positive numbers such as 1, 2, 3, 4,… or logic operators like true/false, and you mustn’t use the empty matrix, 0, negative number and floating point. When you do that, your error can be solved effectively.
"Subscript indices must either be real positive integers or logicals."
is an indication that the index you’re trying to refer to does not exist. It is most likely CointPairs (:,2) doesn’t exist.My suggestion is to place a break point on the line
CointPairs = [rows, cols];
so that you can see the CointPairs matrix. Check to see if the second column exists.We hope this helps.