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에서 Time Series Events에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!