How to non circularly shift at different increments?

Viewed 53

I have a 100x100 array(A) and I am trying to figure how to noncircularly shift them to the right in different increments. For example I want row 1 to shift by none, row 2 by 10, row 3 by 20, row 4 by 30, and row 5 by 40 and for it to repeat this process every 5 rows. How can I achieve this?

A = rand(100,100);
Shift_Factor = ?;
Fill_Value = 0;
[Number_Of_Rows,Number_Of_Columns] = size(A);
A = [A zeros(Number_Of_Rows,Shift_Factor)];
for Row = 1:  Number_Of_Rows
    A(Row,:) = [Fill_Value*ones(1,Shift_Factor) A(Row,1:end-Shift_Factor)];
end

I tried setting Shift_Factor to [0,10,20,30,40] but that didn't work either

1 Answers

I assume this is shift the respective rows to the right. The outer for-loop iterates through the chunks of rows in groups of 5. The inner for-loop iterates from 0 to 4 and creates a variable Row which calculates the target row relative to the Target_Group and Relative_Row. There Shift_Value to be used is calculated relative to the the Relative_Row.

A = rand(100,100);
Fill_Value = 0;

for Target_Group = 1: +5: length(A)
    
    for Relative_Row = 0: 4
        Row = Target_Group+Relative_Row;
        Shift_Value = Relative_Row*10;
        A(Row,:) = [Fill_Value*ones(1,Shift_Value) A(Row,1:end-Shift_Value)];
    end
    
end
Related