필터 지우기
필터 지우기

Changing numbers in a matrix with new numbers

조회 수: 2 (최근 30일)
Sebastian
Sebastian 2014년 2월 1일
댓글: Sebastian 2014년 2월 1일
I have a matrix A:
A=
0 0 1 0 0
1 0 0 0 1
0 0 1 0 1
Then with some functions I find the coordinates of the 1 in the matrix and apply a code, after that those ones wont be ones anymore, will be a different number. How can I put the new numbers in the matrix, changing the ones with the new numbers?
In other words, I would like something like this:
B=
0 0 7 0 0
6 0 0 0 7.6
0 0 8 0 8.1
I am going to put my code for easier understanding. Thank you!

채택된 답변

Walter Roberson
Walter Roberson 2014년 2월 1일
A(logical(A)) = [6 7 8 8.6 8.1];
  댓글 수: 3
Walter Roberson
Walter Roberson 2014년 2월 1일
A = A.';
A(logical(A)) = [2 2.2 2.3 2.4];
A = A.';
MATLAB always goes down columns when assigning multiple values, not across rows.
Sebastian
Sebastian 2014년 2월 1일
Thank you!

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by