Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

cells related

조회 수: 2 (최근 30일)
KSSV
KSSV 2012년 4월 12일
마감: MATLAB Answer Bot 2021년 8월 20일
Hi all
I have 450 matrices of order 4X2. I am saving them in a cell on the name, say Vn. So size of Vn is 450X1. And size of each cell is 4X2. Now I want to run a loop and pick the elements randomly from Vn. For example I want to pick 1, 2, 3, 4 rows from the cells 1, 2, 31 , 32. I can access these elements in the way:
Vn{1}(1,:), Vn{2}(2,:), Vn{31}(3,:) etc. As I am running a loop and picking the values randomly, this kind of calling the rows may take long time for the code to run task. Is there any fast / best way to do this?
Thanks in advance Sreenu

채택된 답변

Andrei Bobrov
Andrei Bobrov 2012년 4월 12일
variant
numcell = randperm(numel(Vn),4);
rows1 = 1:4;
datarnd = arrayfun(@(x,y)Vn{x}(y,:),numcell,rows1,'un',0);
out = cat(1,datarnd{:});

추가 답변 (1개)

Richard
Richard 2012년 4월 12일
pre-allocate memory first, this may speed it up.
  댓글 수: 1
KSSV
KSSV 2012년 4월 12일
Yes it is pre allocated. But thing is some times I may pick two rows from two matrices, or o row from one matrix etc,..it is random...

태그

Community Treasure Hunt

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

Start Hunting!

Translated by