Info

この質問は閉じられています。 編集または回答するには再度開いてください。

REPLACE ELEMENTS OF A MATRIX

5 ビュー (過去 30 日間)
geetha senthil
geetha senthil 2019 年 11 月 7 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
I need to replace the elements of the matrixA=[0 1;0 1} with matrix [1 0;1 0] if the value of elements in matrix A is 0 or with matrix [0 1;0 1] if the value of elements in matrix A is 1 so that i will get a matrix of size 8 x 8 .can you please help with the code.
  3 件のコメント
geetha senthil
geetha senthil 2019 年 11 月 7 日
A =[0 1;0 1];
a=[1 0;1 0];
b=[0 1;0 1 ];
for i = 1:2
for j = 1:2
if A (i , j ) > .5
R( i,j ) = [b] ;
else
R( i,j ) = [a] ;
end
end
end
KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 11 月 7 日

回答 (1 件)

JESUS DAVID ARIZA ROYETH
JESUS DAVID ARIZA ROYETH 2019 年 11 月 7 日
the same way :
matrixA=[0 1;0 1];
s=matrixA==0;
if0=[1 0;1 0];
if1=[0 1;0 1];
R=num2cell(matrixA);
R(s)={if0};
R(not(s))={if1};
R=cell2mat(R)

この質問は閉じられています。

製品

Community Treasure Hunt

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

Start Hunting!

Translated by