Find previous time conditions were met, save it as new marix

1 visualización (últimos 30 días)
SBinary
SBinary el 15 de Nov. de 2018
Comentada: SBinary el 20 de Nov. de 2018
I am working with ecology data. Presence/absence data (Y) has been collected for 100 sites (X) over 10 years (Z), on a rotational basis (30 per year). To illusterate: site X(1) could, for example, be surveyed year [1,4,7,10], site X(2) surveyed year [2,3,4,8], site X(3) surveyed [3,5].
To better explain observed presence/absence (Y) in a given year z I would like to use presence/absence data (Y) from the previous time a given site x was surveyed.
I am at a loss where to begin. Any advice/pointers to get me started would be much appreciated.
Many thanks
J
  4 comentarios
Adam Danz
Adam Danz el 16 de Nov. de 2018
To get all rows numbers where site number 'j' was surveyed, use find(). For example for site number 9:
rowNums = find(X == 9);
rowNums will be a vector of row numbers such as [ 3; 22; 31; 48 ...]; If you're looking at row number 22, the previous time site number 9 was surveyed is in row number 3.
SBinary
SBinary el 19 de Nov. de 2018
Thank you very much, Adam! Question solved. Much appreciated!

Iniciar sesión para comentar.

Respuesta aceptada

Peter Perkins
Peter Perkins el 19 de Nov. de 2018
Joel, it's hard to tell, but it seems very likely that you'd benefit from putting your data in a timetable. "30 per year" sounds like you have timestamps to a resolution smaller than whole years. Timetables let you select data by time.
You could also convert your species and sites to categorical. You might find it more palatable to write
mydata(mydata.Species1=='Cryptobranchus alleganiensis' & mydata.Site=='Oneonta',:)
to select data.
  1 comentario
SBinary
SBinary el 20 de Nov. de 2018
Thanks, Peter. Very useful advice! I still have some way to go from writing code that works, to code that is also elegant and efficient. The reason for working in the data format(s) I was in particular case was to conform to the standard used in the ecological model framework/library I am trying to adapt to my needs. I will definitely try to implement your ideas, though, as they would indeed be beneficial.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by