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?
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)
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 .
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)
I found it today. A is the original matrix sampled by each element of s.
A
Adown=downsample(downsample(A,s)',s)'
It down - vertical matrix sampling, hyphenation, then orthogonal direction sampling, then hyphenation.