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
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
steve 2014년 5월 20일
CLARIFICATION - as you guessed this is a landing gear position signal and a ground interlock signal off an AC. I need to know when -
land(k) = 3 AND land(k+1) = 1,2, or 4...AND
when the above is true ilok(k) = 2 or 3
anytime both of those conditions are met I need to "count" that occurance.
Sorry, total newbie to MATLAB, last time I programmed was in F77, haha. I have never flown an AC where you had an option other than cranking the gear down by hand, haha.

댓글을 달려면 로그인하십시오.

 채택된 답변

Star Strider
Star Strider 2014년 5월 20일

0 개 추천

This seems to work on the test data I’ve given it:
sortedresults = randi(5, 35, 3); % Create Data
sortedresults(:,2) = sortedresults(:,2)-1; % Allow zeros in ‘Land’
DifLand = [diff(sortedresults(:,2)); 0] % Calculate changes in ‘LAND’ state
DxLand = [(1:length(sortedresults))' sortedresults(:,2) DifLand sortedresults(:,3)] % Diagnostic check matrix
Land3ix = find((sortedresults(:,2) == 3) & (ismember(DifLand,[-2 -1 +1]))) % Find indices of changes in ‘LAND’ meeting criteria
Iloc23 = find((sortedresults(:,3) == 2) | (sortedresults(:,3) == 3)) % Find indices of ILOC meeting criteria
LandIlocTrue = intersect(Land3ix, Iloc23) % Indices of ‘LAND’ and ‘ILOC’ meeting criteria
Count = length(LandIlocTrue) % Count occurrences
I left the trailing semicolons off, so it will display the results of each step. Note that it deals with the indices of the rows of the data. All the functions are core MATLAB and do not require any Toolboxes.
The only line that is not necessary in your application code is the ‘DxLand’ matrix. The first column is the row index, the second is ‘LAND’, the third are the end-zero-padded differences in ‘LAND’ (zero-padded to make the vector equal to the others), and the fourth is ‘ILOC’. I created ‘DxLand’ so I could check to be sure the code worked. I ran the code several times to be sure it worked as I understand your criteria.

댓글 수: 6

steve
steve 2014년 5월 20일
thanks very much - will give this a try this afternoon.
Star Strider
Star Strider 2014년 5월 20일
My pleasure!
steve
steve 2014년 5월 20일
hello again - I think I am close. can you tell me what the zero in the code below is doing?
DifLand = [diff(sortedresults(:,2)); 0]
Thanks!
Star Strider
Star Strider 2014년 5월 20일
It makes my ‘DifLand’ variable equal in length to the rest so that MATLAB will be happy concatenating it with the other vectors in ‘DxLand’, and using it in the other statements that need it. (The output of the diff function is shorter than its array argument by whatever number of elements the second argument of diff is, so to get the indices to work out correctly, it’s necessary to pad it. Where to pad it depends on the requirements of the application using it. This is an illustration of the ‘art’ of programming.)
steve
steve 2014년 5월 20일
thanks! Just wanted to understand the purpose of it and that fills the bill!
Star Strider
Star Strider 2014년 5월 20일
My pleasure!
And be sure you always have ‘three in the green’ on short final!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2014년 5월 20일

0 개 추천

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
steve 2014년 5월 20일
thanks, this works. I did not notice before that 2 different folks had responded. Thanks again!
Image Analyst
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에 대해 자세히 알아보기

제품

태그

질문:

2014년 5월 19일

댓글:

2014년 5월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by