replace elements of a matrix with another matrix

7 views (last 30 days)
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 Comments
geetha senthil
geetha senthil on 7 Nov 2019
i am getting an element of matrix replaced by an element and not an element by a matrix.
KALYAN ACHARJYA
KALYAN ACHARJYA on 7 Nov 2019
Edited: KALYAN ACHARJYA on 7 Nov 2019
You didnot provide the answer of my question, what would be the asnwer as per your logic??
Result=??

Sign in to comment.

Accepted Answer

JESUS DAVID ARIZA ROYETH
JESUS DAVID ARIZA ROYETH on 7 Nov 2019
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)

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Products


Release

R2015a

Community Treasure Hunt

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

Start Hunting!