Borrar filtros
Borrar filtros

array assignment question

2 visualizaciones (últimos 30 días)
athpapa -
athpapa - el 10 de Feb. de 2011
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..

Respuesta aceptada

Matt Tearle
Matt Tearle el 11 de Feb. de 2011
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);
  1 comentario
athpapa -
athpapa - el 11 de Feb. de 2011
thank you very much!!This is what I want...

Iniciar sesión para comentar.

Más respuestas (2)

Rob Graessle
Rob Graessle el 10 de Feb. de 2011
So you just want to flip the horizontal orientation of b before you insert it into the same location in a?
a(topRow:topRow+rows-1, leftColumn:leftColumn+columns-1) = fliplr(b);
Is that what you want?

Oleg Komarov
Oleg Komarov el 10 de Feb. de 2011
I assume you wanted to do:
A = zeros(4, 5);
B = ones(2, 4);
szA = size(A);
szB = size(B);
% Align to top left
A(1:szB(1),1:szB(2)) = B
A =
1 1 1 1 0
1 1 1 1 0
0 0 0 0 0
0 0 0 0 0
% Align to top right
A(1:szB(1), 1 + szA(2)-szB(2):end) = B
A =
0 1 1 1 1
0 1 1 1 1
0 0 0 0 0
0 0 0 0 0
EDIT #1
If you want to keep exactly your 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 = 2;
topRow = 3;
% Do the assignment to place it there.
a(topRow:topRow+rows-1, leftColumn:leftColumn+columns-1) = b;
disp(a)
I just changed leftColumn to 2.
Oleg
  1 comentario
athpapa -
athpapa - el 10 de Feb. de 2011
Not exactly. I want with the code that I have to put the table b in the same place as the above code but to start from right to left and not from left to right!If you know how can I do that, you would help me a lot!I have a mistake on my code, the right is:a(topRow:topRow+rows-1, leftColumn:leftColumn+columns-1) = b;
This code put the b table from left to right into the a table. I want the opposite, from right to left, in the same place of the a table!

Iniciar sesión para comentar.

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by