find and replace matrix according vector
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
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
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 NaNs 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!