MATLAB - 将向量转换为矩阵

问题描述 投票:0回答:1

我怎样才能将MATLAB中的矢量转换为这种特定类型的矩阵?列数将是一个参数。

matlab
1个回答
1
投票

您可以构建(一劳永逸)带索引的矩阵(第一列为1:L,第一行为1:K等),然后根据这些索引从数据向量中进行选择

% matrix containing the indices 
indices = bsxfun(@plus,(0:L-1)',(0:K-1)) + 1; % L-by-K matrix
% now get the data from the vector, based on the indices
X=x(indices);
© www.soinside.com 2019 - 2024. All rights reserved.