How to replace 2x2 zero sub matrices by different 2x2 matrices ?
Mostrar comentarios más antiguos
How to replace 2x2 zero submatrix of B with 2x2 matrices different matrice.I have 12 matrices of size 2x2 and want to replace zeros of B by those matrices.
B =
0.8776 0.6513 0 0 0 0 0 0
0.0144 0.8646 0 0 0 0 0 0
0 0 0.2943 0.0560 0 0 0 0
0 0 0.1799 0.8169 0 0 0 0
0 0 0 0 0.9263 0.5289 0 0
0 0 0 0 0.0682 0.6944 0 0
0 0 0 0 0 0 0.5811 0.2124
0 0 0 0 0 0 0.6372 0.5433
Thanks
8 comentarios
Geoff Hayes
el 18 de Mzo. de 2019
parag - do all 2x2 zero matrices get replaced with the same 2x2 (non-zero) matrix? Or are there different replacement matrices?
parag gupta
el 18 de Mzo. de 2019
Editada: parag gupta
el 18 de Mzo. de 2019
Guillaume
el 18 de Mzo. de 2019
Can you describe using matlab syntax (so we can easily copy/paste into matlab) what your inputs are. In your example, above
%this is valid matlab:
B = [0.8776 0.6513 0 0 0 0 0 0
0.0144 0.8646 0 0 0 0 0 0
0 0 0.2943 0.0560 0 0 0 0
0 0 0.1799 0.8169 0 0 0 0
0 0 0 0 0.9263 0.5289 0 0
0 0 0 0 0.0682 0.6944 0 0
0 0 0 0 0 0 0.5811 0.2124
0 0 0 0 0 0 0.6372 0.5433]
In particular, it's not clear how you define your replacements. Have you got 12 replacements matrices? How are they stored? Easiest would be a cell array:
replacements = {[1 2; 3 4], [5 6; 7 8], etc...} %not valid syntax currently!
If it's a cell array how do we know where replacement{5} (for example) goes ?
parag gupta
el 18 de Mzo. de 2019
Editada: Guillaume
el 18 de Mzo. de 2019
parag gupta
el 18 de Mzo. de 2019
Guillaume
el 18 de Mzo. de 2019
The loop would imply that you want to create 12 matrices. However, since it overwrites the matrices in the previous step, you'll end up with only 3 matrices. The ones created on the last step of the loop.
While you say that you have 12 matrices, your I want solution in this form implies that there are only 3 matrices, which are rotated on each row.
A bit confusing as to what you have.
I doubt it will be difficult to do what you want, but the method will vary depending on exactly what it is that you want. So, please clarify.
parag gupta
el 18 de Mzo. de 2019
Editada: parag gupta
el 18 de Mzo. de 2019
Respuesta aceptada
Más respuestas (1)
Here is a simple example, but the right hand side can be any array with an appropriate number of elements
B(B==0)=1:48;
9 comentarios
parag gupta
el 18 de Mzo. de 2019
Editada: parag gupta
el 18 de Mzo. de 2019
You said you have 12 matrices in your original post.
B(B==0)=cat(3,p1,p2,p3,...,p12);
Note that it is probably going to continue to be awkward if you hold the matrices in separate variables.
parag gupta
el 18 de Mzo. de 2019
B(B==0)=cat(3,p1,p2,p3,...,p12);
Note that it is probably going to continue to be awkward if you hold your matrices in separate variables.
parag gupta
el 18 de Mzo. de 2019
Matt J
el 18 de Mzo. de 2019
I have showed you how.
Matt J
el 18 de Mzo. de 2019
B(B==0)=cat(3,p1,p2,p3,...,p12);
parag gupta
el 18 de Mzo. de 2019
Matt J
el 18 de Mzo. de 2019
How many elements does the right hande side have?
Categorías
Más información sobre Matrices and 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!