find and replace matrix according vector

조회 수: 1 (최근 30일)
alize beemiel
alize beemiel 2020년 11월 10일
댓글: alize beemiel 2020년 11월 10일
hi everyone
i have
vector x and matrix A
x = [1 2 3 7 8 9 13 22 30 ]
A =[1 3 6 9
2 12 13 8
3 3 6 7
4 22 31 30
5 8 9 33 ]
and i want to have value in matrix A accordding a vector x
and replace it by a new value like to add 10000
without changing a first column in A
i want this resultat
A =[1 10003 6 10009
2 12 10013 10008
3 10003 6 10007
4 10022 31 10030
5 10008 10009 33 ]
and thanks

답변 (1개)

Stephen23
Stephen23 2020년 11월 10일
x = [1,2,3,7,8,9,13,22,30];
A = [1,3,6,9;2,12,13,8;3,3,6,7;4,22,31,30;5,8,9,33];
ida = ismember(A,x);
ida(:,1) = false;
A(ida) = A(ida)+1000
A = 5×4
1 1003 6 1009 2 12 1013 1008 3 1003 6 1007 4 1022 31 1030 5 1008 1009 33

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by