MATLAB: Finding the largest index in an array that is divisible by a certain number

array

Hi,
Given an nx1 array, I'm trying to get matlab to determine the largest index value which is divisible by a number (say 3), and then have matlab truncate the array to that point.
Any suggestions?
Thanks, Charles

Best Answer

divisor = 3;
new_array = old_array(1 : end - mod(end,divisor));