I have a matrix in MATLAB from which I want to sample every other entry:
a =
1 5 9 13
2 6 10 14
3 7 11 15
4 8 12 16
And I want:
result =
1 9
3 11
How can I do this without a for loop?
Select Random Subset of Matrix Columns X = randn(10,1000); Create the random number stream for reproducibility within datasample . s = RandStream('mlfg6331_64'); Randomly select five unique columns from X .
To take a random sample from a matrix in R, we can simply use sample function and if the sample size is larger than the number of elements in the matrix replace=TRUE argument will be used.
Description. y = randsample( n , k ) returns k values sampled uniformly at random, without replacement, from the integers 1 to n . y = randsample( population , k ) returns a vector of k values sampled uniformly at random, without replacement, from the values in the vector population .
: x(t) = 4cos(200πt), at sampling frequency equal to 400 Hz and then to plot the sampled signal x[n], consider 10 cycles of x(t).
A matrix is a two-dimensional array of numbers. In MATLAB, you create a matrix by entering elements in each row as comma or space delimited numbers and using semicolons to mark the end of each row. For example, let us create a 4-by-5 matrix a −
For example, to refer to the element in the 2 nd row and 5 th column, of the matrix a, as created in the last section, we type − MATLAB will execute the above statement and return the following result −
To do that, we need to separate each row with semicolon (;) as shown below − Here 2 4 6 is the first row, 3 6 9 is the second row and 4 8 12 is the third row. The matrix will be as follows − Let us now execute the same in MATLAB command prompt, as mentioned below −
This instruction set explains how to solve a matrix equation and perform statistical analysis on a matrix in MATLAB. The matrix equations will be in the form Ax=B. The statistical analysis will find the total number of data points as well as the minimum, maximum, and range. In addition, it will include the sum, mean, and standard deviation.
I don't know of a multi-dimensional way to do it automatically, but Matlab's indexing is good enough if you're happy to specify it for each dimension:
a(1:2:end,1:2:end)
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