How many zeros do I have before a specific sting variable?

1 回表示 (過去 30 日間)
antonet
antonet 2012 年 8 月 15 日
Dear all
I have
A={
[0]
[0]
[0]
[0]
[0]
[0]
[0]
[0]
[0]
[0]
[0]
[0]
[0]
[0]
[0]
[0]
[0]
[0]
[0]
[0]
[0]
[0]
[0]
[0]
[0]
[0]
[0]
[0]
[0]
[0]
[0]
[0]
[0]
[0]
[0]
[0]
[0]
[0]
[0]
' b1'
' b1'
' b1'
' b1'
' b1'
'b1'
' b1'
[0]
[0]
[0]
'b1'
' b1'}
I have this cell vector. This vector has a characteristic. Immediately after the first zeros the letter 'b1' begins. So I would like to count the zeros before the first 'b1' that starts to appear in this vector. In this case I have 39 zeros. Is it possible to calculate this number using a Matlab code?
thanks

採用された回答

Andrei Bobrov
Andrei Bobrov 2012 年 8 月 15 日
yourzeros = find(cellfun(@ischar,A),1,'first')-1;

その他の回答 (3 件)

Matt Fig
Matt Fig 2012 年 8 月 15 日
編集済み: Matt Fig 2012 年 8 月 15 日
T = strfind(cellfun(@(x) ~x(1),A).',[1 0])
Notice that T will show you the index of every zero that is followed by a nonzero. So you want T(1).

Azzi Abdelmalek
Azzi Abdelmalek 2012 年 8 月 15 日
min(find(cellfun(@(x) ~isnumeric(x),A)))-1

Oleg Komarov
Oleg Komarov 2012 年 8 月 15 日
Another solution:
pos = strfind([A{:}],'b')-1
pos(1)
  2 件のコメント
Andrei Bobrov
Andrei Bobrov 2012 年 8 月 16 日
Hi Oleg! may be in this case so?
pos = strfind([A{:}],' ')-1
pos(1)
Oleg Komarov
Oleg Komarov 2012 年 8 月 16 日
I assumed the ' ' was a typing error :)

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

カテゴリ

Help Center および File ExchangeOperators and Elementary Operations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by