how can access?

hi,
i have array , each row in this array contains data as follow: "1|Toy Story (1995)|01-Jan-1995||http://us.imdb.com/M/title-exact?Toy%20Story%20(1995)|0|0|0|1|1|1|0|0|0|0|0|0|0|0|0|0|0|0|0"
I want access to sequence of zero's and one's and ignore what before it in order to place these sequence into new vector.
who can help me?
thanks

回答 (2 件)

Fangjun Jiang
Fangjun Jiang 2011 年 9 月 11 日

0 投票

If those 0s and 1s are always at the end and their repetition is consistent, you could do the following.
str='1|Toy Story (1995)|01-Jan-1995||http://us.imdb.com/M/title-exact?Toy%20Story%20(1995)|0|0|0|1|1|1|0|0|0|0|0|0|0|0|0|0|0|0|0'
NewStr=str(end-37:end);
NewStr=NewStr(2:2:end);
NewStr=str2num(NewStr')
Otherwise, use regexp()
Movie={'1|Toy Story (1995)|01-Jan-1995||http://us.imdb.com/M/title-exact?Toy%20Story%20(1995)|0|0|0|1|1|1|0|0|0|0|0|0|0|0|0|0|0|0|0';
'2|GoldenEye (1995)|01-Jan-1995||http://us.imdb.com/M/title-exact?GoldenEye%20(1995)|0|1|1|0|0|0|0|0|0|0|0|0|0|0|0|0|1|0|0';
'3|Four Rooms (1995)|01-Jan-1995||http://us.imdb.com/M/title-exact?Four%20Rooms%20(1995)|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|1|0|0'}
Found=regexp(Movie,'(\|[01]\|)+.+','match');
Data=cell(size(Found));
for k=1:size(Found,1)
temp=Found{k};
Data{k}=temp{1}(2:2:end)-'0';
end

5 件のコメント

Walter Roberson
Walter Roberson 2011 年 9 月 11 日
Variant:
NewStr = str(end-37:end);
NewStr = NewStr(2:2:end) - '0';
with the str2num not required.
Fangjun Jiang
Fangjun Jiang 2011 年 9 月 11 日
Thanks, Walter! I kept forgetting this trick.
huda nawaf
huda nawaf 2011 年 9 月 11 日
thanks, but what is 37, what is meaning
is 37 remining if deal with another row? such as :
02|GoldenEye(1995)|01-Jan-1995||http://us.imdb.com/M/title-exact?GoldenEye%20(1995)|0|1|1|0|0|0|0|0|0|0|0|0|0|0|0|0|1|0|03|FourRooms(1995)|01-Ja
thanks
Fangjun Jiang
Fangjun Jiang 2011 年 9 月 11 日
In the example code in my answer, str contains one long string which is the information regarding one movie record. 37 means the last 37 characters which contain '|0|0|1...'. Run the code one line a time to see the result.
Fangjun Jiang
Fangjun Jiang 2011 年 9 月 12 日
See update using regexp()

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

Walter Roberson
Walter Roberson 2011 年 9 月 11 日

0 投票

barpos = find(str == '|');
nums = str(barpos(5)+1:2:end) - '0';
Be careful, though, as the number of flags appears to be inconsistent. I count one more on the first example than in the second, if I assume that the '03|FourRooms...' is really the start of a new record that you have accidentally joined together with the GoldenEye row.

カテゴリ

ヘルプ センター および File ExchangeCharacters and Strings についてさらに検索

タグ

質問済み:

2011 年 9 月 11 日

Community Treasure Hunt

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

Start Hunting!

Translated by