longest wet and dry spell of the matrix

2 ビュー (過去 30 日間)
marie
marie 2012 年 12 月 3 日
I have the following matrix a=
[99 99 0.100 0.120 0 0.500 0;
0 0 0 0 0.150 0.120 0;
0.110 0.010 0.010 0 0 0.300 0.100;
0 0.250 0 0.050 0.060 0.100 0.110;
0 0.120 0.040 0 0.500 0.750 99];
I want to find the longest wet and dry spell of the matrix of each row ( the longest days in a row that it rained and it did not rain)...
I have
i=1;1:5
d=(a(i,:)~=0 & a(i,:)<99)
the 1's form the answer tell me how many days in a row did rain but I don't know how to make a code that will return which week had the longest days in a row that it rained and it did not rain

採用された回答

Image Analyst
Image Analyst 2012 年 12 月 4 日
編集済み: Image Analyst 2012 年 12 月 4 日
Once again, this is a situation that would be trivial if you had the Image Processing Toolbox because in one line of code you can find the lengths of all non-zero stretches of rainfall for a column. One more line of code would tell you the longest of those stretches. Do you have that toolbox? Type ver to find out. If you do, try this code:
a=[99 99 0.100 0.120 0 0.500 0;
0 0 0 0 0.150 0.120 0;
0.110 0.010 0.010 0 0 0.300 0.100;
0 0.250 0 0.050 0.060 0.100 0.110;
0 0.120 0.040 0 0.500 0.750 99]
[rows columns] = size(a);
for row = 1 : rows
measurements = regionprops(a(row, :)< 99 & a(row, :) > 0, 'Area');
% Get all the stretches of rain
allRains = [measurements.Area]
% Get the longest rain.
longestStretch = max(allRains);
fprintf('For row %d, the longest stretch with rain = %d.\n\n', ...
row, longestStretch);
end
In the command window:
allRains =
2 1
For row 1, the longest stretch with rain = 2.
allRains =
2
For row 2, the longest stretch with rain = 2.
allRains =
3 2
For row 3, the longest stretch with rain = 3.
allRains =
1 4
For row 4, the longest stretch with rain = 4.
allRains =
2 2
For row 5, the longest stretch with rain = 2.
  3 件のコメント
marie
marie 2012 年 12 月 4 日
Thank you!
Image Analyst
Image Analyst 2012 年 12 月 4 日
You're welcome, but, well, did it work? If so, mark it as "Answered".

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

その他の回答 (0 件)

カテゴリ

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