MATLAB: How to apply function on columns while skipping certain columns

columnsfunctionmatrix manipulation

So I have a matrix that has 31413 rows and 950 columns. I want to apply a function starting from column 2 till column 10, skipping column 11, then applying the same function from coumn 12 till column 20, then skipping column 21 and applying the function on column 22 till column 30 and so on.
Basically something like this
[col1 col2…col10 col11 col12…col20 col21 col22…col30 and so on until column 950]
(the columns in between are where I want to apply the function basically)
Is there any way I can do this? Any help appreciated!!!

Best Answer

Hi Zuha,
You can use a for loop as below and it does what is required, provided you expect the same amount of size in rows and columns from the anonymous function:
m = rand(31413,950);
for i = 2:10:size(m,2)
m(:,i:i+8) = anonymousFun(m(:,i:i+8)); % anonymousFun could be tril, provided you wanted to get the same size of matrix
end
Hope this helps.
Regards,
Sriram