PLEASE HELP - how to COUNT occurances
古いコメントを表示
Hello,
I have an array (sortedresults) which has 3 columns (time, land, ilok) and each contains integer values. In column 2 (land) I need to COUNT the number of times that integer changes from 3 to anything else EXCEPT zero, AND verify the value of column 3 (ilok) is either the value of 2 or 3. When both conditions are met I need to add 1 to my COUNT.
Thanks in advance!
2 件のコメント
Star Strider
2014 年 5 月 19 日
Please clarify: In column 2 (land) I need to COUNT the number of times that integer changes from 3 to anything else EXCEPT zero...
Does the direction of the change matter, i.e. does that only mean the change from row k to row k+1 or from row k-1 to row k, either, or both?
Gear-up landings can really take the fun out of your day! (I had to drop the gear by hand once. Fortunately it locked down.)
steve
2014 年 5 月 20 日
採用された回答
その他の回答 (1 件)
Image Analyst
2014 年 5 月 20 日
How about this:
sortedresults = randi(5, 300, 3); % Create sample data.
% Extract columns 2 and 3.
land = sortedresults(:, 2)
ilok = sortedresults(:, 3)
% Find where ilok column has a value of 2 or 3.
ilok2or3 = ilok == 2 | ilok == 3
% Find the change from one element to the next in column 2
diffland = diff(land)
% Find where the value is 3 in land, and the difference is not 0 or -3
% and column 3 = 2 or 3.
land3 = (land(1:end-1) == 3) & (diffland ~=0 & diffland ~= 03) & ilok2or3(1:end-1)
% Sum up the result.
result = sum(land3)
2 件のコメント
steve
2014 年 5 月 20 日
Image Analyst
2014 年 5 月 20 日
You're welcome. It's good to scroll all the way down the screen to make sure you see all responses.
カテゴリ
ヘルプ センター および File Exchange で Mathematics についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!