How to detect number of zero string in a cell

3 ビュー (過去 30 日間)
Fateme Jalali
Fateme Jalali 2016 年 1 月 18 日
コメント済み: Star Strider 2016 年 1 月 18 日
Hi,I attached my matlab code and database. I want to count howmany '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' happens in diffr

採用された回答

Star Strider
Star Strider 2016 年 1 月 18 日
There are no zero strings in your data. I assume you want to find out which are the same in the two files. You can do that easily enough by converting them to character arrays and using the intersect function:
fidi1 = fopen('Fateme Jalali t2.txt');
tt1 = textscan(fidi1,'%s', 'delimiter', '\n');
fclose(fidi1);
fidi2 = fopen('Fateme Jalali t3.txt');
tt2 = textscan(fidi1,'%s', 'delimiter', '\n');
fclose(fidi2);
tt1s = char(tt1{:});
tt2s = char(tt2{:});
[C,ia,ib] = intersect(tt1s,tt2s,'rows','stable');
If you want to find out which ones are not the same, use the setdiff function instead of intersect:
[C,ia] = setdiff(tt2s,tt1s,'rows','stable');
You will probably have to experiment to get the result you want, but one of these should work for you.
  2 件のコメント
Fateme Jalali
Fateme Jalali 2016 年 1 月 18 日
thank u so much
Star Strider
Star Strider 2016 年 1 月 18 日
My pleasure!

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

その他の回答 (1 件)

Image Analyst
Image Analyst 2016 年 1 月 18 日
編集済み: Image Analyst 2016 年 1 月 18 日
Anyway, to count the number of zeros in a line of text from your file, you can do this to one line of text
numZeros = sum(textLine == '0');
To count the number of contiguous regions of zeros (so like [0 0 0 0] would be one region instead of 4), you'd use bwlabel():
[L, numZeroRegions] = bwlabel(textLine == '0');

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by