Why this error message? Subscript indices must either be real positive integers or logicals.

Why do i get this error message
Subscript indices must either be real positive integers or logicals.
for i = 1:numel(matrix_a)
handles.index_a = matrix_a(i)
handles.index_b = matrix_b(i)
for somthin
[u v] = function(var_u(handles.index_a, handles.index_b)var_v(handles.index_a, handles.index_b))
end
end
pls help

2 Comments

well it looks like the "somthin" you use in the 2nd loop is not made up of real positive integers or logicals. Can you show what it is?

Answers (1)

Just a guess, but ...
You are using handles.index_a and handles.index_b as indices into var_u and var_v. Because handles.index_a traces back to matrix_a, I am guessing that matrix_a (or b) has some entries that are not positive integers, and therefore cannot be used as an index.

4 Comments

I think that's it. Also Antonio, if this is actual code, not pseudocode, you need a comma before var_v and you can't name functions "function" since that's a reserved word.
thats right. matrix_a and matrx_b are both 52x52 matrices. matrix_a has the first column just zeros and in matrix_b ist the first row filled with zeroes. How can i make it right. Any idea
no thats just pseudocode, there is a comma and the function name is another
There is a conceptual error in your code, that I don't think we can fix for you. If the first column of matrix_a has a zero, then it cannot be an index. The code simply needs to be rewritten such that you really only access the indices you want.

This question is closed.

Asked:

on 25 Aug 2014

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!