How to select specific row in a matrix

7 ビュー (過去 30 日間)
Ikra89
Ikra89 2013 年 2 月 11 日
Hi all..
i have a problem to select every row.
for eg:
i have matrix 100x13.
i want to select data which position in row 1-5, 21-25, 41-45, 61-65, 81-85.
so i have 2 new matrixs. first as i described above, and the second is the rest (6-20, 26-40, 46-60, 66-80, 86-100).
i want to apply k-fold method to get training data and testing data.
thanks a lot if somebody can help me.
regards
Ikra

回答 (2 件)

Shashank Prasanna
Shashank Prasanna 2013 年 2 月 11 日
A = rand(100,4);
ind_logical = logical(ones(100,1));
ind_logical([1:5, 21:25, 41:45, 61:65, 81:85])=false;
B = A(~ind_logical,:);
C = A(ind_logical,:);
  2 件のコメント
Jan
Jan 2013 年 2 月 11 日
true(100, 1) is more efficient than creating a double array at first and convert it ino a logical. But the logical indexing is an efficient method here in general: +1.
Ikra89
Ikra89 2013 年 2 月 13 日
編集済み: Ikra89 2013 年 2 月 13 日
i try to change A = rand(100,4) to fix dimension become 75x13 and 25x13, but the output is different from the real data.
in this case i just want to select data, not to change. thanks a lot for your answer, but if you can fix it, i really appreciate your help.

サインインしてコメントする。


Thorsten
Thorsten 2013 年 2 月 11 日
編集済み: Thorsten 2013 年 2 月 11 日
X = rand(100, 13);
ind0 = 1:5; ind1 = ind0;
for i = 1:4, ind1 = [ind1 ind0 + 20*i]; end
ind2 = setdiff(1:100, ind1);
A = X(ind1, :);
B = X(ind2, :);
  1 件のコメント
Ikra89
Ikra89 2013 年 2 月 13 日
編集済み: Ikra89 2013 年 2 月 13 日
wrong answer. your program not too different with benji bowbow in above. why the output is different with the data? in this case i just want to select data, not to change. thanks a lot for your answer, but if you can fix it, i really appreciate your help.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by