How to change cell arrays to 3D arrays in order to speed up calculations?

조회 수: 2 (최근 30일)
Mantas Vaitonis
Mantas Vaitonis 2018년 7월 2일
댓글: Guillaume 2018년 7월 3일
Hello, For example I have two cell arrays x {10}(20x5) non integer values and k {10}(5x1) integer values 1:5, and use one cell array as index to other array.
x1=cellfun(@(x,y) x(5,y),x,k, 'UniformOutput',false);
and result is x1 {10}(1x5), unfortunately cell fun is slow with gpuArray when working with bigger arrays, what would be the way to use 3D arrays and maybe arrayfun for this?
  댓글 수: 1
Guillaume
Guillaume 2018년 7월 3일
Mantas Vaitonis's comment mistakenly posted as an answer moved here:
An example would be if
x(:,:,1)
1 8 10 2 5
3 5 7 9 11
4 5 2 3 7
12 10 4 6 2
9 7 10 1 3
.....
and k(:,:,1)
3
4
1
5
3
then x1(:,:1) would be
10 1 9 3 10

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

답변 (1개)

KL
KL 2018년 7월 2일
편집: KL 2018년 7월 2일
Convert x into a 3d matrix using
x_mat = cat(3,x{:});
and then if you want to extract 5th row from all the pages,
x_mat(5,:,:) %squeeze(x_mat(5,:,:)) , if you want a 2D matrix
  댓글 수: 1
Mantas Vaitonis
Mantas Vaitonis 2018년 7월 2일
It is not that only 5th row is needed, but columns indexes should be taken from k {10}(5x1) where integer values from 1 to 5, that x(5,k(:,1,:),:).

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

카테고리

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