replacing any value in a matrix

조회 수: 2 (최근 30일)
Muhammad Haziq
Muhammad Haziq 2019년 1월 16일
댓글: Muhammad Haziq 2019년 1월 16일
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
Walter Roberson
Walter Roberson 2019년 1월 16일
A(k,4)==10
That is a comparison, not an assignment. Assignment uses =

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

채택된 답변

Walter Roberson
Walter Roberson 2019년 1월 16일
A(A>4) = 10;
No loop needed.

추가 답변 (0개)

카테고리

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

태그

제품


릴리스

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by