필터 지우기
필터 지우기

Pick a random column according to specific class data

조회 수: 3 (최근 30일)
Yousif Alaraji
Yousif Alaraji 2023년 3월 25일
댓글: Image Analyst 2023년 3월 27일
I have matrix lets say
1 1 2 2 3 3 4 4
5 8 3 7 2 8 3 9
4 6 8 2 3 4 6 7
2 3 6 7 3 4 6 8
I want to randomly pick columns from each first row class [1 2 3 4]

답변 (1개)

Image Analyst
Image Analyst 2023년 3월 25일
Try randi
A = [...
1 1 2 2 3 3 4 4
5 8 3 7 2 8 3 9
4 6 8 2 3 4 6 7
2 3 6 7 3 4 6 8];
[rows, columns] = size(A);
% Get random column indexes
randomColumns = randi(columns, rows, 1)
randomColumns = 4×1
2 1 5 7
% Get values of A there
randomValues = zeros(rows, 1);
for row = 1 : rows
randomValues(row) = A(row, randomColumns(row));
end
randomValues
randomValues = 4×1
1 5 3 6
  댓글 수: 2
Yousif Alaraji
Yousif Alaraji 2023년 3월 26일
편집: Yousif Alaraji 2023년 3월 26일
Many thanks,
but can I get one column from each specified Number
1 1 2 2 3 3 4 4
I have these classified columns and I just want random
1 2 3 4
Image Analyst
Image Analyst 2023년 3월 27일
Not sure what you're asking. I thought I answered it but maybe you want unique.

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

카테고리

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