How to replace 2x2 zero sub matrices by different 2x2 matrices ?

3 ビュー (過去 30 日間)
parag gupta
parag gupta 2019 年 3 月 18 日
編集済み: parag gupta 2019 年 3 月 18 日
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 件のコメント
Guillaume
Guillaume 2019 年 3 月 18 日
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
parag gupta 2019 年 3 月 18 日
編集済み: parag gupta 2019 年 3 月 18 日
oops, u r right it will overwites the matrices.Could u pls tell what to do so that I end up with all 12 matrices?
sorry for the confusion, I want this matrix at the end.
x matrix 1 matrix 2 matrix 3
matrix 4 x matrix 5 matrix 6
matrix 7 matrix 8 x matrix 9
matrix 10 matrix 11 matrix 12 x
thanks you so much :)

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

採用された回答

Matt J
Matt J 2019 年 3 月 18 日
編集済み: Matt J 2019 年 3 月 18 日
basically i want solution in this form
x p1 p2 p3
p1 x p2 p3
p1 p2 x p3
p1 p2 p3 x
C={zeros(2), p1,p2,p3};
result=B+cell2mat( C(toeplitz(1:4)) );
  3 件のコメント
Matt J
Matt J 2019 年 3 月 18 日
Very similar to things I've already mentioned:
B(B==0)=cat(3,matrix4,matrix7,matrix10,matrix1,matrix8,matrix11,...
matrix2,matrix5,matrix12,matrix3,matrix6,matrix9);
parag gupta
parag gupta 2019 年 3 月 18 日
thank you so much . :)
haha..sorry for the confusion.
thanks again for all your help..love u :)

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

その他の回答 (1 件)

Matt J
Matt J 2019 年 3 月 18 日
編集済み: Matt J 2019 年 3 月 18 日
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 件のコメント
parag gupta
parag gupta 2019 年 3 月 18 日
Unable to perform assignment because the left and right sides have a different number of elements.
got this error. ;(
Matt J
Matt J 2019 年 3 月 18 日
How many elements does the right hande side have?

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

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by