필터 지우기
필터 지우기

How to randomize the row of a table directly ?

조회 수: 44 (최근 30일)
Tuong Nguyen Minh
Tuong Nguyen Minh 2020년 6월 19일
답변: madhan ravi 2020년 6월 19일
Dear Matlab users,
Currently I am puting my matrix A into the table T like this and now I want to shuffle the row of this table.
clc;
A = [1 2 3;4 5 6;7 8 9;10 11 12;13 14 15]
T = array2table(A,'VariableNames',{'First_Collumn','Second_Collumn','Third_Collumn'})
Is there anyway to do this directly on this table instead of having to shuffle the data before putting data in a table like below ?
Thank you
%% Shufle A
% B is the shuffle version of A
[NumRow,NumCol] = size(A);
% Randomize the row
index = randperm(NumRow);
B = A(index,:)
T_Shuffle = array2table(B,'VariableNames',{'First_Collumn','Second_Collumn','Third_Collumn'})

채택된 답변

madhan ravi
madhan ravi 2020년 6월 19일
B = T(randperm(size(A,1)), :)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Tables에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by