MATLAB Answers

0

replacing any value in a matrix

Asked by Muhammad Haziq on 16 Jan 2019
Latest activity Commented on by Muhammad Haziq on 16 Jan 2019
I have 3x7 matrix. I want to replace any number by 10 (which is greater than 4). I write this code but its not working. Can any body help me ?
A=[1,2,5,2,3,4,2; 4,2,1,5,3,2,3; 1,4,2,3,2,2,1];
% 1 2 5 2 3 4 2
% 4 2 1 5 3 2 3
% 1 4 2 3 2 2 1
for k=1:1:3
if A(k,4)>4
A(k,4)==10
end
end
expected result:
% 1 2 5 2 3 4 2
% 4 2 1 10 3 2 3
% 1 4 2 3 2 2 1

  1 Comment

A(k,4)==10
That is a comparison, not an assignment. Assignment uses =

Sign in to comment.

Tags

Products


Release

R2017a

1 Answer

Answer by Walter Roberson
on 16 Jan 2019
 Accepted Answer

A(A>4) = 10;
No loop needed.

  1 Comment

Sign in to comment.