Replacing Values of a Larger Matrix with that of a Smaller Matrix

3 ビュー (過去 30 日間)
Richard Zareck
Richard Zareck 2017 年 9 月 10 日
回答済み: Jose Marques 2017 年 9 月 10 日
I have a matrix A that looks like:
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
and a matrix B that looks like:
0 0
0 0
0 0
0 0
0 0
0 0
How can I create a new matrix C that looks like:
0 0 1 1 0 0 1 1 0 0
0 0 1 1 0 0 1 1 0 0
0 0 1 1 0 0 1 1 0 0
0 0 1 1 0 0 1 1 0 0
0 0 1 1 0 0 1 1 0 0
0 0 1 1 0 0 1 1 0 0
by inserting B into A and without using loops. Also if this is not possible, is there a way to create matrix C from matrix A?

採用された回答

Cedric
Cedric 2017 年 9 月 10 日
編集済み: Cedric 2017 年 9 月 10 日
b = mod( floor( (0:size( A, 2 )-1)/2 ), 2 ) ;
C = bsxfun( @times, A, b ) ;
Note that the way I define b=00110011.. is ... shows that I am tired!
  2 件のコメント
Richard Zareck
Richard Zareck 2017 年 9 月 10 日
Thank you!!
Cedric
Cedric 2017 年 9 月 10 日
My pleasure. I answered thinking that you wanted to "mask" columns of A, hence the multiplication by 0 and 1 of given columns. Let me know if the purpose was different.

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

その他の回答 (1 件)

Jose Marques
Jose Marques 2017 年 9 月 10 日
imgSiz = [x1,y1];
blkSiz = [x1,size_column];
numRep = imgSiz./blkSiz;
basMat = toeplitz(mod(0:numRep(1)-1,2),mod(0:numRep(2)-1,2));
mask(:,:) = repelem(basMat,x1,size_column);

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by