replace elements of a matrix with another matrix

조회 수: 7 (최근 30일)
geetha senthil
geetha senthil 2019년 11월 7일
댓글: Patrick Rousseau 2021년 9월 2일
Hai
I need to replace the element of matrix 'A' by matrix 'a' if the value of the element is greater than 50 and by matrix 'b' if the value is less than 50,so that i will get a 32x32 matrix.I have given the code below.Help me please.thanks
A = randi (100 , 16 , 16) ;
a=[5 5;5 5];
b=[20 20;20 20 ];
for i = 1:16
for j = 1:16
if A (i , j ) > 50
R( i,j ) = [a] ;
else
R( i,j ) = [b] ;
end
end
end
  댓글 수: 3
geetha senthil
geetha senthil 2019년 11월 7일
i am getting an element of matrix replaced by an element and not an element by a matrix.
KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 11월 7일
편집: KALYAN ACHARJYA 2019년 11월 7일
You didnot provide the answer of my question, what would be the asnwer as per your logic??
Result=??

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

채택된 답변

JESUS DAVID ARIZA ROYETH
JESUS DAVID ARIZA ROYETH 2019년 11월 7일
solution :
A = randi (100 , 16 , 16) ;
s=A>50;
a=[5 5;5 5];
b=[20 20;20 20 ];
R=num2cell(A);
R(s)={a};
R(not(s))={b};
R=cell2mat(R)
  댓글 수: 2
geetha senthil
geetha senthil 2019년 11월 7일
It is working...thank u...
Patrick Rousseau
Patrick Rousseau 2021년 9월 2일
Thanks for this! Helped me out aswell.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

제품


릴리스

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by