add a constant value for all columns for selected rows

51 ビュー (過去 30 日間)
Damith
Damith 2016 年 5 月 20 日
コメント済み: Damith 2016 年 5 月 20 日
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;
  1 件のコメント
Damith
Damith 2016 年 5 月 20 日
Thanks. That's exactly what I want.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by