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??

采纳的回答

Walter Roberson
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 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by