필터 지우기
필터 지우기

How to get a random 50x14 matrix from 300x14 matrix

조회 수: 1 (최근 30일)
Amirali AGHAMIRI
Amirali AGHAMIRI 2022년 3월 27일
댓글: Amirali AGHAMIRI 2022년 3월 28일
Hello,
Could you please tell me how to get a random 50x14 matrix from 300x14 matrix?
  댓글 수: 4
Scott MacKenzie
Scott MacKenzie 2022년 3월 27일
@Amirali AGHAMIRI, @Torsten has posted an answer. Perhaps that is what you are after

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

채택된 답변

Image Analyst
Image Analyst 2022년 3월 27일
Perhaps this, if you want all 50 rows to be adjacent to each other and not randomly chosen.
% Define matrix.
m = randi(9, 300, 14)
% Get starting and ending rows
startingRow = randi(size(m, 1)-49, 1, 1)
endingRow = startingRow + 49
% Extract a band of 50 contiguous rows
m50 = m(startingRow : endingRow, :);
  댓글 수: 3
Image Analyst
Image Analyst 2022년 3월 28일
So just delete the first line where I created an m. I just did that because you keep forgetting to attach your actual matrix in a .mat file with the paperclip icon.
% Get starting and ending rows
startingRow = randi(300-49, 1, 1)
startingRow = 207
endingRow = startingRow + 49
endingRow = 256
As you can see above when I ran it, it would take all rows between 207 and 256 of your original matrix and extract them to a new matrix called m50. Why do you think that will not work for your matrix?
Amirali AGHAMIRI
Amirali AGHAMIRI 2022년 3월 28일
Thanks, it works.

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

추가 답변 (1개)

Torsten
Torsten 2022년 3월 27일
편집: Torsten 2022년 3월 27일
A = rand(300,14);
p = randperm(300,50);
B = A(p,:)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by