フィルターのクリア

Finding strings in a 21 x 1 cell array.

2 ビュー (過去 30 日間)
JE
JE 2015 年 10 月 13 日
編集済み: Mohammad Abouali 2015 年 10 月 13 日
I have a cell array that looks like this:newsequence =
'CGT'
'GAC'
'AGT'
'CCT'
'CTC'
'CTT'
'TAC'
'CGA'
'AAG'
'GGA'
'AGA'
'ATA'
'AAA'
'GTG'
'GCG'
'TGA'
'TGC'
'ATT'
'ACG'
'CCT'
'GCA'
I am interested in finding the location of 'TAC'. When I use this function: found=strfind(newsequence,'TAC'); I end up with a cell array with all zeros and a 1 in the 7th row. I want it to display a 7 because that is the location of 'TAC', but I can't seem to figure it out.

採用された回答

Mohammad Abouali
Mohammad Abouali 2015 年 10 月 13 日
編集済み: Mohammad Abouali 2015 年 10 月 13 日
newsequence = {'CGT'
'GAC'
'AGT'
'CCT'
'CTC'
'CTT'
'TAC'
'CGA'
'AAG'
'GGA'
'AGA'
'ATA'
'AAA'
'GTG'
'GCG'
'TGA'
'TGC'
'ATT'
'ACG'
'CCT'
'GCA'};
mask=strcmpi(newsequence ,'TAC');
rows=find(mask)
rows =
7
or you could combine both command in one as:
rows=find( strcmpi(newsequence ,'TAC') )

その他の回答 (2 件)

Star Strider
Star Strider 2015 年 10 月 13 日
The function is returning a logical array of row indices. To convert it to a numerical value for the actual row number of every matching row, add a call to the find function:
found = find(strfind(newsequence,'TAC'));
I didn’t specifically test this, but it should work.
  2 件のコメント
JE
JE 2015 年 10 月 13 日
Undefined function 'find' for input arguments of type 'cell'.
I tried this already. :(
Star Strider
Star Strider 2015 年 10 月 13 日
This looks tortured, but it works:
found = (strfind(newsequence,'TAC'));
found = find(cell2mat(cellfun(@(x)~isempty(x), found, 'Uni',0)))
found =
7

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


Image Analyst
Image Analyst 2015 年 10 月 13 日
Try ismember(). Here I'm using CCT to show what happens if you have the string in more than one row:
ca = {'CGT'
'GAC'
'AGT'
'CCT'
'CTC'
'CTT'
'TAC'
'CGA'
'AAG'
'GGA'
'AGA'
'ATA'
'AAA'
'GTG'
'GCG'
'TGA'
'TGC'
'ATT'
'ACG'
'CCT'
'GCA'}
[ia, ib] = ismember(ca, 'CCT')
rows = find(ia)
  1 件のコメント
JE
JE 2015 年 10 月 13 日
rows =
[]
I keep getting this as the answer.

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

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by