Why is my modulus giving me an error: Index in position 1 exceeds array bounds (must not exceed 1).
2 views (last 30 days)
Show older comments
Juniper Sohn
on 11 Jul 2019
Answered: Walter Roberson
on 11 Jul 2019
Hi all, I am trying to figure out if my modulus is working properly - I am iterating through a 2D array that has 220 columns (=col), and want to extract mod(col,12)
for col = 1:size(AU,2) %220 columns (with some months missing)
mod = mod(col,12);
if mod == 0
mod = 12;
end
%1
end
After running this code on Livescript, these are the value that I get on my command window:
col = 2
mod = 1
So it seems that the code only iterated once and got stuck in the second iteration. And I get an error like this in my command window: Index in position 1 exceeds array bounds (must not exceed 1).
Could you pleae explain to me how to fix this issue so that I can iterate through all the 220 columns??
0 Comments
Accepted Answer
Walter Roberson
on 11 Jul 2019
mod = mod(col,12);
After the first of those, mod is no longer a function because you have assigned a number to mod
0 Comments
More Answers (0)
See Also
Categories
Find more on Matrix Indexing 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!