Array indices must be positive integers or logical values.
2 views (last 30 days)
Show older comments
gcoord
0 0
0 0
0 0
0 0
.........
Array indices must be positive integers or logical values.
this error is coming please help
0 Comments
Answers (1)
Steven Lord
on 8 May 2023
Usually this happens when you try to use 0 as an index. Indices in MATLAB start at 1 not 0.
x = 1:10;
This will work:
y(1:2:20) = x.^2
This won't. I've wrapped it in try and catch so code later in this answer can run.
try
z(0:2:19) = x.^2
catch ME
fprintf("This code threw error: %s\n", ME.message)
end
To fix this error, use indices that start at 1 not 0.
Alternately you could be trying to call a function but there's a variable by that name instead. In this case rename the variable so it doesn't have the same name as the function.
q = sin(pi)
sin = 42;
w = sin(pi)
If you need further help you will need to show us a small sample of code with which you can reproduce this error.
0 Comments
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!