I have array like this: y=[00110011100001110011] I need search in array, and if it is sequence [..11..] then i get 5, if it sequence [..111...] then I should get 6. In the answer I should got sequence something like this:[..5665556...] So maybe know how do that?

 採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 11 月 23 日
編集済み: Azzi Abdelmalek 2013 年 11 月 23 日

0 投票

y='00110011100001110011'
ii={'' '5' '6'}
out=char(ii(cellfun(@numel,regexp(y,'1+','match'))))'
%or
y='00110011100001110011';
a=[0 y-'0' 0];
ii5=strfind(a,[0,1,1,0]);
ii6=strfind(a,[0,1,1,1,0]);
v(ii6)=6;
v(ii5)=5;
v(~v)=[];

2 件のコメント

Povilas
Povilas 2013 年 11 月 23 日
Thanks for answer. It works, but if I have that array [00110011100001111111] And I need that result be 5, if it is in interval from 11 to 1111?
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 11 月 23 日
y='00110011100001111111001111101111'
n=7; % maximal number of consecutive 1
ii=repmat({'6'},1,n+1)
ii(2:4)={'5'}
out=char(ii(cellfun(@numel,regexp(y,'1+','match'))))'

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

その他の回答 (2 件)

Andrei Bobrov
Andrei Bobrov 2013 年 11 月 23 日
編集済み: Andrei Bobrov 2013 年 11 月 23 日

0 投票

out = sprintf('%d',strfind([y '0'],'10')-strfind(['0' y],'01')+4)
ADD
out = sprintf('%d',(strfind([y '0'],'10')-strfind(['0' y],'01')>3) + 5)
Povilas
Povilas 2013 年 11 月 23 日
編集済み: Povilas 2013 年 11 月 24 日

0 投票

but where y='00110011100001111111001111101111' it is not in '' but in [array2] and cant read from that array
Now my code is:
x = [Masyvas];
x >= 0.14
y1=double(ans)
z=y1'
y=num2str(z)
%y=u(find(~isspace(u)))
r = y(y ~= ' ') %delete space
n=18; % maximal number of consecutive 1
ii=repmat({'6'},1,n+1);
ii(8:13)={'5'};
out=char(ii(cellfun(@numel,regexp(r,'1+','match'))))
And get error:
??? Index exceeds matrix dimensions.
Error in ==> Untitled at 27
out=char(ii(cellfun(@numel,regexp(r,'1+','match'))))

4 件のコメント

Andrei Bobrov
Andrei Bobrov 2013 年 11 月 25 日
What is it Masyvas? Please small example for Masyvas.
Povilas
Povilas 2013 年 11 月 25 日
編集済み: Povilas 2013 年 11 月 25 日
masyvas
Image Analyst
Image Analyst 2013 年 11 月 25 日
Do you expect him to type that in? Unlikely. Please make it easy for him to help you by attaching the csv or workbook file.
Povilas
Povilas 2013 年 11 月 26 日
add array file.

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

カテゴリ

タグ

質問済み:

2013 年 11 月 23 日

コメント済み:

2013 年 11 月 26 日

Community Treasure Hunt

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

Start Hunting!

Translated by