如何在matlab中从2d单元格中选择和删除单元格

时间:2012-12-06 18:50:19

标签: matlab select random cells

我有一个35x2矩阵(随机字);我随机选择了8行(rndm)。我需要做的是从randomwords矩阵中删除8个选定的行并将这个新的27x2矩阵保存在一个新的变量标题下,但我发现这非常困难。我提供了我的代码任何帮助将不胜感激。

target = words ([30 1 46 14 44 55 8 3 57 65 69 70 57 39 21 60 22 20 16 10 9 17 62 19 25 41 49 53 36 6 42 58 40 56 63]);
synonym = words([43 15 32 28 72 27 48 51 13 67 59 33 35 47 52 61 71 7 23 12 2 66 11 37 4 45 64 38 34 31 29 18 50 68 26]);
% assigns these elements of words into targets and synonyms.  They are
% ordered so that words and synonyms are corresponding elements of
% synonyms and targets


% TO SELECT 8 RANDOM WORDS FOR THE ENCODING PHASE

randomwords = [target; synonym]';   % should be a 35x2 matrix
rndm = datasample(randomwords, 8, 1);    % should select 8 random couples from the rows and none of them will be repeats 
unpaired = rndm(:,2);     % should select only the synonyms to form the unpaired stimuli; will be different for each run

1 个答案:

答案 0 :(得分:1)

将已删除行的索引存储在变量中,假设为removedrows,然后执行:

result = randomwords;

result(removedrows,:) = [];