histc problem

3 ビュー (過去 30 日間)
Mohammad Golam Kibria
Mohammad Golam Kibria 2011 年 6 月 7 日
Hi, I have a matrix as follows:
I =
1 1 1 8 8 1 2
1 8 8 8 8 2 1
1 8 8 8 2 1 1
1 8 8 8 1 1 1
2 2 2 1 1 1 1
2 2 2 1 1 1 1
then the following code give me a error:
index= I==8; histc(index(:),1)
gives the follwing error.
??? Error using ==> histc First input must be non-sparse numeric array.
How to solve this?
Thanks

回答 (1 件)

Walter Roberson
Walter Roberson 2011 年 6 月 7 日
I'm not sure what you think you are going to accomplish with that, but
index = 0 + (I==8);
histc(index(:),1)
  2 件のコメント
Mohammad Golam Kibria
Mohammad Golam Kibria 2011 年 6 月 7 日
your code give the proper output that i want.but why the following syntax is necessary:
index = 0 + (I==8);
Mohammad Golam Kibria
Mohammad Golam Kibria 2011 年 6 月 7 日
actually I have tow matrix I and I1.
I have some values having 1. and I1 is a binary matrix having
0 and 1. I need two know how many 1s are there in I1 where
the values of I have 1s. Is there any easy code

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

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by