2017-08-03 12 views
-2

ここで何が起こっているのか誰かが説明できますか? 私はY(:、1)がYの値の最初の列であることを知っています。 しかしY(p、1)はどういう意味ですか? MatlabのnoobのMatlab行列アクセス列

Y = load('testFile.txt'); %Load file 
p = randperm(length(Y)); %List of random numbers between 0 and Y size 

Y(:,1) = Y(p,1); 
Y(:,2) = Y(p,2); 
Y(:,3) = Y(p,4); 

答えて

1
Y = load('testFile.txt'); %Load file 
% create a mapping to shuffle the rows of Y. 
% This assumes more rows than columns in Y, otherwise the code doesn't make sense. 
% This is because length(Y) returns the length of the largest dimension. 
% A more robust implementation would use size(Y,1) rather than length(Y). 
p = randperm(length(Y)); %List of random numbers between 0 and Y size 

% Rearrange the rows of column 1 based on the shuffled order 
Y(:,1) = Y(p,1); 
% Rearrange the rows of column 2 based on the shuffled order 
Y(:,2) = Y(p,2); 
% Set the third column to the shuffled fourth column. 
Y(:,3) = Y(p,4); 
+0

ありがとうございました@jodag – llebpmac