Sampling a large matrix using column indices

1 view (last 30 days)
I am trying to sample a large(17x16602) matrix for use as a kernel for a kernel kmeans algorithm. Because the matrix is very large(and full), I decided sample it randomly. I now have a list of 1000 column indices which I want to use to extract data from my matrix. I have tried all of the simple indexing techniques, but all I am getting are the values within the first row that I want. What I have so far is:
L=length(x);
IDX_RAND=randperm(L);
IDX_SAMP=IDX_RAND(1:1000);
What I want is to use the column values in IDX_SAMP to extract a 17x1000 matrix for use in my kernel. The desired result would return the column value in IDX_SAMP and preserve the trailing 16 rows in that column. Any help or clarification requests are appreciated. Thanks!

Accepted Answer

Walter Roberson
Walter Roberson on 26 Dec 2012
If you are looking for the value of the same columns for each of the rows, then
x(:, IDX_SAMP)
Note: I advise you to use L = size(x,2) instead of L = length(x) as length() does not always choose the same dimension.
  1 Comment
Jacob Moses
Jacob Moses on 26 Dec 2012
Thank you, this is exactly what I needed. And I'll keep in mind using size for this project.

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!