Azzera filtri
Azzera filtri

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

1 visualizzazione (ultimi 30 giorni)
Hello,
Could you please tell me how to get a random 50x14 matrix from 300x14 matrix?
  4 Commenti
Scott MacKenzie
Scott MacKenzie il 27 Mar 2022
@Amirali AGHAMIRI, @Torsten has posted an answer. Perhaps that is what you are after

Accedi per commentare.

Risposta accettata

Image Analyst
Image Analyst il 27 Mar 2022
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 Commenti
Image Analyst
Image Analyst il 28 Mar 2022
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?

Accedi per commentare.

Più risposte (1)

Torsten
Torsten il 27 Mar 2022
Modificato: Torsten il 27 Mar 2022
A = rand(300,14);
p = randperm(300,50);
B = A(p,:)

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by