Finding the position of a row vector in an array

1 回表示 (過去 30 日間)
Rekha
Rekha 2013 年 5 月 20 日
Hi
I have a 1x127 row vector in variable S and have read a 500x127 array from excel spreadsheet into variable V. Then i'm checking if S exists in V using function ' ismember '. If it returns a value 1, I need to find the location of S in the excel spreadsheet and then replace it by new vector Y.
For example:
Consider a small array,
A=[1 0 1 1 1;
1 1 0 1 0;
1 0 1 1 0;
0 1 0 1 1;
0 0 1 0 1];
S=[1 0 1 1 0];
val=ismember(S,A);
Y=[1 1 1 1 1];
This will return 1. Now how can I find the location of [1 0 1 1 0] which is 3rd row here and then insert Y inplace of [1 0 1 1 0] in A, so that the modified matrix will be:
A=[1 0 1 1 1;
1 1 0 1 0;
1 1 1 1 1;
0 1 0 1 1;
0 0 1 0 1];
I want to know the location of S in A considering S as one single entity.
Thank you.

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 5 月 20 日
編集済み: Azzi Abdelmalek 2013 年 5 月 20 日
[idx,idx]=ismember(A,[1 0 1 1 0],'rows')
A(logical(idx),:)=[1 1 1 1 1]
  1 件のコメント
Rekha
Rekha 2013 年 5 月 20 日
Thank you...

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by