Matlab矩阵访问列

时间:2017-08-03 17:18:46

标签: matlab

有人可以解释这里发生了什么吗? 我知道Y(:,1)是Y中的第一列值。 但Y(p,1)是什么意思? Matlab noob

boost

1 个答案:

答案 0 :(得分: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);