Delete columns from a matrix

4 ビュー (過去 30 日間)
Bill Symolon
Bill Symolon 2018 年 4 月 7 日
コメント済み: Bill Symolon 2018 年 4 月 7 日
Hello, all. I know there are several posts about reducing matrices, but I haven't found one that answers my question. I have two matrices: class1 is 29x284214 and class2 is 29x492. I need to randomly delete columns from class1 until it has same number of columns as class2. I've tried the following code, but it's not very efficient and I'm hoping you can show me a better way.
if true
while length(class1) > length(class2)
index = randi(length(class1));
class1(:,index) = [];
end
end
I do not need to keep the original class1 matrix. Thanks for any help you can provide.

採用された回答

David Fletcher
David Fletcher 2018 年 4 月 7 日
diff=size(class1,2)-size(class2,2)
deletionList=randperm(size(class1,2),diff)
class1(:,deletionList)=[]
  1 件のコメント
Bill Symolon
Bill Symolon 2018 年 4 月 7 日
Perfect, thanks!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by