Replacing elements of a matrix
Mostrar comentarios más antiguos
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 comentarios
Andrei Bobrov
el 20 de Nov. de 2017
Do you want get a 30 x 30 matrix?
Santosh Nath
el 20 de Nov. de 2017
yes. I think 30*30 matrix is the only possible option in this case
Respuestas (2)
Walter Roberson
el 20 de Nov. de 2017
0 votos
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 comentarios
Santosh Nath
el 20 de Nov. de 2017
Thanks fore the ans. I shall try your suggestion.
Walter Roberson
el 20 de Nov. de 2017
newMatrix = kron(YourMatrix, [1 1;1 1]);
newMatrix(I*2-1:I*2, J*2-1:J*2) = TwoByTwoMatrixFor(I,J)
Andrei Bobrov
el 20 de Nov. de 2017
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);
Categorías
Más información sobre Multidimensional Arrays en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!