How to shuffle two matrices in a consistent manner

4 ビュー (過去 30 日間)
raf
raf 2021 年 10 月 20 日
コメント済み: raf 2021 年 10 月 20 日
I am using the fisher iris data set:
load fisheriris
X = meas
Y = species
P = randperm(length(X));
X = X(P);
Y = Y(P);
I want to shuffle the data such that if the first entry in X is [5.1 3.5 1.4 0.2] and it's corresponding Y is ['setosa'] then if that X entry is shuffled to say the 30th row, then the same corresponding Y entry is also shuffled to the 30th row.
Currently the code seems to work for Y but returns X as a row vector of 150 columns which makes sense per the documentation but I don't know how to change it to achieve my workflow. Any help would be great, thanks.

採用された回答

Jan
Jan 2021 年 10 月 20 日
I assume, X is a matrix and you want to shuffle the rows. Then:
X = X(P, :);
% ^
  1 件のコメント
raf
raf 2021 年 10 月 20 日
my hero, thank you

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

その他の回答 (0 件)

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by