How to choose a matrix in MATLAB?

I have a matrix in MATLAB from which I want to try every other record:

a = 1 5 9 13 2 6 10 14 3 7 11 15 4 8 12 16 

I want too:

 result = 1 9 3 11 

How can I do this without a for loop?

+6
matrix matlab
source share
4 answers

I don’t know a multidimensional way to do this automatically, but Matlab indexing is good enough if you are happy to specify it for each dimension:

 a(1:2:end,1:2:end) 
+12
source share

This should work for your specific example:

 result = a([1 3],[1 3]); 

and more usually:

 result = a(1:2:size(a,1),1:2:size(a,2)); 

You can learn more about indexing in MATLAB here .

+5
source share
 samples_x = floor(linspace(1, size(a,1), new_Nx)); samples_y = floor(linspace(1, size(a,2), new_Ny)); new_a = a(samples_x,samples_y) 
+1
source share

I found it today. A is the original matrix sampled by each element of s.

 Adown=downsample(downsample(A,s)',s)' 

It down - vertical matrix sampling, hyphenation, then orthogonal direction sampling, then hyphenation.

+1
source share

All Articles