MATLAB:定义矩阵的 n 个子集
我有一个 1974x1 向量 Upper
,我试图将信息分解为每个包含 36 个项目的单独数组。因此,我使用 length 发现有 1974 个项目,然后除以 36 并使用 floor
函数。我不知道如何用 n
完成这一切。
这是我的逻辑:我定义 n 是为了找到需要定义的子集的数量。然后,我试图让subsetn 成为subset1、subset2、...、subset36。然而,MATLAB仅将矩阵subsetn定义为1x36矩阵。然而,该矩阵包含subset1 应该包含的内容(1...36)。你们对新手有什么建议吗?我做错了什么?
binSize = 36;
nData = length(Upper);
nBins = floor(nData/36);
nDiscarded = nData - binSize*nBins;
n=1:binSize;
subsetn= [(n-1)*binSize+1:n*binSize];
I have a 1974x1 vector, Upper
, and I am trying to break the information up into individual arrays of 36 items each. So, I used length to find that there are 1974 items and then divided by 36 and used the floor
function. I cannot figure out how to do it all with n
.
Here is my logic: I am defining n
in an attempt to find the number of subsets that need to be defined. Then, I am trying to have subsetn become subset1, subset2,...,subset36. However, MATLAB only definies the matrix subsetn as a 1x36 matrix. However, this matrix contains what subset1 is supposed to contain(1...36). Do you guys have any advice for a newbie? What am I doing wrong?
binSize = 36;
nData = length(Upper);
nBins = floor(nData/36);
nDiscarded = nData - binSize*nBins;
n=1:binSize;
subsetn= [(n-1)*binSize+1:n*binSize];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以创建一个 54x36 数组,其中第 n 列是您的第 n 子集。
您可以通过
subsetArray(:,n)
访问第 n 个子集You can create a 54x36 array where the
n
th column is yourn
th subset.You can access the
n
th subset assubsetArray(:,n)
如果我误解了你想要做什么,请提前抱歉。
我认为下面的小技巧可能会达到您想要的效果(这很hacky,但我不是Matlab专家):
现在
inds
是一个nBins*binSize索引矩阵。您可以使用它对 Upper 进行索引,这样您就可以将子集作为结果矩阵中的列。
编辑:看到尤达的答案,他的更好;)
Sorry in advance if I misunderstood what you want to do.
I think the following little trick might do what you want (it's hacky, but I'm no Matlab expert):
Now
inds
is a nBins*binSize matrix of indices. You can index Upper with it likewhich should give you the subsets as the columns in the resulting matrix.
Edit: on seeing Yoda's answer, his is better ;)