add a constant value for all columns for selected rows

52 vues (au cours des 30 derniers jours)
Damith
Damith le 20 Mai 2016
Commenté : Damith le 20 Mai 2016
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;

Réponse acceptée

the cyclist
the cyclist le 20 Mai 2016
You need
A(i1z,:)=A(i1z,:)+7000;
  1 commentaire
Damith
Damith le 20 Mai 2016
Thanks. That's exactly what I want.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by