Sampling a large matrix using column indices

조회 수: 2 (최근 30일)
Jacob Moses
Jacob Moses 2012년 12월 26일
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!

채택된 답변

Walter Roberson
Walter Roberson 2012년 12월 26일
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
Jacob Moses
Jacob Moses 2012년 12월 26일
Thank you, this is exactly what I needed. And I'll keep in mind using size for this project.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by