I have a rather simplistic example that I would like to learn the best possible solution for. I have a data set:
depth = [0:0.5:20];
I want to only select 'depth' from a specific range, for example from 2 to 5. I can do this by:
d1 = find(depth == 2,1,'first');
d2 = find(depth == 5,1,'first');
depth = depth(d1:d2);
Is there an alternative, cleaner way of doing this?
y = range( X ,'all') returns the range of all elements in X . y = range( X , dim ) returns the range along the operating dimension dim of X . For example, if X is a matrix, then range(X,2) is a column vector containing the range value of each row.
n = numel( A ) returns the number of elements, n , in array A , equivalent to prod(size(A)) .
just use logical indexing:
depth(depth >= 2 & depth <= 5)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With