Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I sample a matrix in MATLAB?

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?

like image 872
Nathan Fellman Avatar asked Nov 24 '09 06:11

Nathan Fellman


People also ask

How do you randomly sample a matrix in MATLAB?

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 .

How do you randomly sample a matrix?

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.

How do you create a sample in MATLAB?

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 .

How do you use sampling in MATLAB?

: 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).

How to create a matrix in MATLAB?

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 −

How to refer to the element in a matrix in MATLAB?

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 −

How to separate each row in a matrix using MATLAB command prompt?

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 −

How do I perform statistical analysis on a matrix in MATLAB?

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.


1 Answers

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)
like image 180
Will Robertson Avatar answered Sep 22 '22 04:09

Will Robertson