MATLAB: Array assignment question

leftcolumnrightcolumn

I have this code:
a = zeros(4, 5);
b = ones(2, 4);
[rows columns] = size(b);
% Define upper left of where I want to place array b
leftColumn = 1;
topRow = 3;
% Do the assignment to place it there.
a(topRow:topRow+rows-1, leftcolumn:leftColumn-columns-1) = b;
disp(a)
How can I change it to define the right Column and not the left? I tried many changes but I have not found it yet! Thank you..

Best Answer

So, this is what you want?
a = zeros(4, 5);
b = ones(2, 4);
[rows columns] = size(b);
% Define upper left of where I want to place array b
rightColumn = 4;
topRow = 3;
% Do the assignment to place it there.
a(topRow:(topRow+rows-1), (rightColumn-columns+1):rightColumn) = b;
disp(a)
Or do you want the columns of b flipped? In which case, just replace = b; with = fliplr(b);