add a constant value for all columns for selected rows

53 次查看(过去 30 天)
Hi,
I need to add a constant value (7000) to a selected rows as identified by the logical array index. But, I want to perform something like shown in the example below.
Example:
A =
1010001 10 20 30 40 50 60
1010002 100 200 300 400 500 600
1010003 5 6 7 8 9 10
1010004 1 2 3 4 5 6
B =
1010002
1010004
Output =
1010001 10 20 30 40 50 60
1010002 7100 7200 7300 7400 7500 7600
1010003 5 6 7 8 9 10
1010004 7001 7002 7003 7004 7005 7006
I have a code as shown below BUT this does NOT produce the output I want like in C
i1z=ismember(A(:,1),B);
A=A(i1z,:)+7000;

采纳的回答

the cyclist
the cyclist 2016-5-20
You need
A(i1z,:)=A(i1z,:)+7000;

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by