フィルターのクリア

array assignment question

2 ビュー (過去 30 日間)
athpapa -
athpapa - 2011 年 2 月 10 日
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..

採用された回答

Matt Tearle
Matt Tearle 2011 年 2 月 11 日
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 件のコメント
athpapa -
athpapa - 2011 年 2 月 11 日
thank you very much!!This is what I want...

サインインしてコメントする。

その他の回答 (2 件)

Rob Graessle
Rob Graessle 2011 年 2 月 10 日
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 2011 年 2 月 10 日
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 件のコメント
athpapa -
athpapa - 2011 年 2 月 10 日
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!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by