Hi,
I would like to know how to calculate the number of zeros in an array and stop when the array value is one.
Example: a = [0 0 0 0 1 1 1 0 0 0]
here, there are 4 zeros before it meet array value of one.
then, let say I convert binary to RGB, 0=green and 1=red. The same thing goes here...how I want to calculate green pixel before it meet red pixel.
Anybody can give any idea. Thank you in advanced.

1 件のコメント

marlina
marlina 2011 年 8 月 15 日
Let say if 0 remain black, only 1 turn to green. How to calculate black pixel before it meet the first pixel of green?

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

 採用された回答

dhyun
dhyun 2011 年 8 月 15 日

1 投票

one method you could use is to find the first position where a == 1 and then subtract 1 from it:
num_zeros = find(a == 1, 1) - 1;

4 件のコメント

marlina
marlina 2011 年 8 月 15 日
Thanks,
for binary its working.
How about in RGB?
Paulo Silva
Paulo Silva 2011 年 8 月 15 日
find(diff(a)==1) %green transition to red
find(diff(a)==-1) %red transition to green
Paulo Silva
Paulo Silva 2011 年 8 月 15 日
find(diff(a)) %gives two index values, green to red and red to green
marlina
marlina 2011 年 8 月 15 日
Thanks,
I tried it but some error occurred.
Let say if 0 remain black, only 1 turn to green. How to calculate black pixel before it meet the first pixel of green?

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

その他の回答 (0 件)

カテゴリ

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

タグ

質問済み:

2011 年 8 月 15 日

Community Treasure Hunt

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

Start Hunting!

Translated by