How many zeros do I have before a specific sting variable?
显示 更早的评论
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
采纳的回答
更多回答(3 个)
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
2012-8-15
min(find(cellfun(@(x) ~isnumeric(x),A)))-1
Oleg Komarov
2012-8-15
Another solution:
pos = strfind([A{:}],'b')-1
pos(1)
2 个评论
Andrei Bobrov
2012-8-16
Hi Oleg! may be in this case so?
pos = strfind([A{:}],' ')-1
pos(1)
Oleg Komarov
2012-8-16
I assumed the ' ' was a typing error :)
类别
在 帮助中心 和 File Exchange 中查找有关 Programming Utilities 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!