Matlab "Index in position 1 is invalid. Array indices must be positive integers or logical values."

37 views (last 30 days)
I keep getting this error message
" Index in position 1 is invalid. Array indices must be positive integers or logical values.
Error in loop_Practice (line 48)
if x(i,j)>maximum(k) "
I am very new to Matlab, so I am not even sure what the error message is saying. Can anyone help me?
I have attached the matlab file.

Accepted Answer

Jon
Jon on 18 Feb 2020
Edited: Jon on 18 Feb 2020
The error is telling you that MATLAB thinks that the variable that you call maximum is a vector, and that you want to have element k of this vector, but k is not a positive integer, so the expression is not valid.
It looks like you want to find the maximum value of some elements. If so, you should be using the max function for this, not a variable called maximum.
If you include the rest of your code (please use the code button on the MATLAB Answers toolbar to format it nicely) it might be possible to see exactly what is going wrong.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!