Replacing elements of a matrix

Hello, I have a 15*15 matrix of all zeros.I want to replace each element of the matrix with different 2*2 matrices. How can it be done?
Thanks

댓글 수: 2

Andrei Bobrov
Andrei Bobrov 2017년 11월 20일
Do you want get a 30 x 30 matrix?
Santosh Nath
Santosh Nath 2017년 11월 20일
yes. I think 30*30 matrix is the only possible option in this case

댓글을 달려면 로그인하십시오.

답변 (2개)

Walter Roberson
Walter Roberson 2017년 11월 20일

0 개 추천

That cannot be done. Numeric matrices must have scalars at each position.
It would be possible to convert the numeric matrix to a cell array and then replace the cell contents. num2cell() would do the conversion to cell.

댓글 수: 2

Santosh Nath
Santosh Nath 2017년 11월 20일
Thanks fore the ans. I shall try your suggestion.
newMatrix = kron(YourMatrix, [1 1;1 1]);
newMatrix(I*2-1:I*2, J*2-1:J*2) = TwoByTwoMatrixFor(I,J)

댓글을 달려면 로그인하십시오.

Andrei Bobrov
Andrei Bobrov 2017년 11월 20일

0 개 추천

InitData = randi(150,2,2,15,15);
out = reshape(permute(InitData,[1 3 2 4]),30,[]);
or
InitData = arrayfun(@(x)randi(150,2,2),ones(15),'un',0);
out = cell2mat(InitData);

카테고리

도움말 센터File Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

질문:

2017년 11월 19일

답변:

2017년 11월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by