Why is my modulus giving me an error: Index in position 1 exceeds array bounds (must not exceed 1).
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Walter Roberson
2019-7-11
mod = mod(col,12);
After the first of those, mod is no longer a function because you have assigned a number to mod
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!