add a constant value for all columns for selected rows

52 Ansichten (letzte 30 Tage)
Damith
Damith am 20 Mai 2016
Kommentiert: Damith am 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;

Akzeptierte Antwort

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

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by