【问题标题】:Iterating through dimensions in MATLAB在 MATLAB 中遍历维度
【发布时间】:2012-03-21 19:49:46
【问题描述】:

如何将这些命令简化为MATLAB 中的一行?

medoidContainer(:, i, 1) = squeeze(reshape(container(:, :, 1),1, y * x));
medoidContainer(:, i ,2) = squeeze(reshape(container(:, :, 2),1, y * x));
medoidContainer(:, i ,3) = squeeze(reshape(container(:, :, 3),1, y * x));

通过它们,我将RGB 图像重塑为单行矩阵(每种颜色)。但是如何在不必遍历每个维度的情况下做到这一点呢?


我试过了:

medoidContainer(:, i ,1:3) = squeeze(reshape(container(:, :, 1:3),1, y * x));

但这不起作用。

【问题讨论】:

  • 这里的目的不是很清楚。您是否尝试将 M x N x 3 数组转换为 (M*N) x 3 数组?
  • @OliCharlesworth,是的(变量 i 是使用它的循环的一部分,并遍历图像列表)。

标签: matlab image-processing multidimensional-array


【解决方案1】:

听起来您正在尝试将 M x N x 3 数组转换为 (M*N) x 3 数组。你可以这样做:

a = reshape(container, [M*N 3]);

要将它分配到您的“容器”中,我认为您需要这个:

medoidContainer(:,i,:) = a;

【讨论】:

  • 做到了!我用它作为medoidContainer(:, i, :) = reshape(container, [y*x 3]);,就像一个魅力。谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-12-08
  • 1970-01-01
  • 2017-04-30
  • 2012-04-12
  • 2011-04-21
  • 2010-10-20
相关资源
最近更新 更多