Is there an easy way to extract every nth element of a vector in MATLAB? Say we have
x = linspace(1,10,10);
Is there a command something like
y = nth(x,3)
so that y = 3 6 9
?
Cheers!
M = mean( A , 'all' ) computes the mean over all elements of A . This syntax is valid for MATLAB® versions R2018b and later. M = mean( A , dim ) returns the mean along dimension dim . For example, if A is a matrix, then mean(A,2) is a column vector containing the mean of each row.
M = min( A ) returns the minimum elements of an array. If A is a vector, then min(A) returns the minimum of A . If A is a matrix, then min(A) is a row vector containing the minimum value of each column of A .
n = numel( A ) returns the number of elements, n , in array A , equivalent to prod(size(A)) .
Try this:
x = linspace(1, 10, 10);
n = 3;
y = x(1 : n : end); % => 1 4 7 10
y = x(n : n : end); % => 3 6 9
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