select specific values from a matrix based on indeces
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi all,
I have a matrxi of 4*37800. I want to keep specific values based on two indeces.
The first index shows the rows that i want to keep and the second the columns every 15 steps. I mean that i split the 37800 columns to groups of 15 the index shows which column of each group i want to keep.
How can i isolate the values based on the two indeces?
I attach the folders.
iMxR is the index showing the rows that i want. ix is the index showing which colum i need. freq is the matrix.
Thank you for your help.
댓글 수: 2
Tommy
2020년 6월 4일
If the first index in ix is 14:
>> ix(1)
ans =
14
and the first 15 indices in iMxR are the following:
>> iMxR(1:15)
ans =
1 1 2 2 2 2 2 3 3 3 2 1 1 1 1
then which values should be pulled from the first 4x15 block of frequencies? Is the following correct?
frequencies(1, 14)
frequencies(1, 14)
frequencies(2, 14)
frequencies(2, 14)
frequencies(2, 14)
frequencies(2, 14)
frequencies(2, 14)
frequencies(3, 14)
...and so on
채택된 답변
Tommy
2020년 6월 4일
I believe this will give you the values you want:
temp = reshape(iMxR, 15, [])';
idx = sub2ind(size(temp), 1:size(temp,1), ix);
row = temp(idx); % row(i) is the row of the ith 4x15 block
col = ix; % col(i) is the column of the ith 4x15 block
temp = reshape(frequencies, 4, 15, []); % convert frequencies to a bunch of 4x15 blocks
idx = sub2ind(size(temp), row, col, 1:size(temp,3)); % convert row and col to linear indices of temp
val = temp(idx); % pull out the relevant values
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Lookup Tables에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!