PLEASE HELP - how to COUNT occurances
Mostrar comentarios más antiguos
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 comentarios
Star Strider
el 19 de Mayo de 2014
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
el 20 de Mayo de 2014
Respuesta aceptada
Más respuestas (1)
Image Analyst
el 20 de Mayo de 2014
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 comentarios
steve
el 20 de Mayo de 2014
Image Analyst
el 20 de Mayo de 2014
You're welcome. It's good to scroll all the way down the screen to make sure you see all responses.
Categorías
Más información sobre Mathematics en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!