在元胞数组中应用 Movmedian
Applying Movmedian Within Cell Array
我有一个名为 "output" 的元胞数组 (2 x 6),第 1 行 {1 -> 6, 2} 中的每个元胞都包含一个 1024 x 1024 x 100 矩阵。我想将 movmedian 应用于第 1 行中的每个单元格。我想在 window 大小 = 5 的维度 = 3 中应用此函数。
output = cellfun(@movmedian(5,3), output,'uniform', 0);
这是我到目前为止想出的代码,但是,它会产生 "unbalenced or unexpected parenthesis or bracket" 错误。我不确定是什么导致了这个错误。我也有点不确定如何指示 matlab 仅对元胞数组的第 1 行执行此操作,请帮忙!
感谢您的宝贵时间!!
function handle passed as the first argument to cellfun
will be sequentially passed the contents of each cell (i.e. each 3-D matrix). Since you need to also pass the additional parameters needed by movmedian
, you should create an anonymous function像这样:
@(m) movmedian(m, 5, 3)
其中输入参数 m
是 3-D 矩阵。如果你想将它应用到 output
的第一行,你只需要 index the cell array 像这样:
output(1, :)
这将 return 包含第一行 output
的元胞数组,其中 :
表示 "all columns"。如果您想将修改后的矩阵存储回 output
.
的相同单元格中,则可以在赋值中使用相同的索引
综上所述,这是解决方案:
output(1, :) = cellfun(@(m) movmedian(m, 5, 3), output(1, :),...
'UniformOutput', false);
...避免必须指定 'UniformOutput', false
的一个小技巧是将匿名函数的结果封装在元胞数组中:
output(1, :) = cellfun(@(m) {movmedian(m, 5, 3)}, output(1, :));
我有一个名为 "output" 的元胞数组 (2 x 6),第 1 行 {1 -> 6, 2} 中的每个元胞都包含一个 1024 x 1024 x 100 矩阵。我想将 movmedian 应用于第 1 行中的每个单元格。我想在 window 大小 = 5 的维度 = 3 中应用此函数。
output = cellfun(@movmedian(5,3), output,'uniform', 0);
这是我到目前为止想出的代码,但是,它会产生 "unbalenced or unexpected parenthesis or bracket" 错误。我不确定是什么导致了这个错误。我也有点不确定如何指示 matlab 仅对元胞数组的第 1 行执行此操作,请帮忙!
感谢您的宝贵时间!!
function handle passed as the first argument to cellfun
will be sequentially passed the contents of each cell (i.e. each 3-D matrix). Since you need to also pass the additional parameters needed by movmedian
, you should create an anonymous function像这样:
@(m) movmedian(m, 5, 3)
其中输入参数 m
是 3-D 矩阵。如果你想将它应用到 output
的第一行,你只需要 index the cell array 像这样:
output(1, :)
这将 return 包含第一行 output
的元胞数组,其中 :
表示 "all columns"。如果您想将修改后的矩阵存储回 output
.
综上所述,这是解决方案:
output(1, :) = cellfun(@(m) movmedian(m, 5, 3), output(1, :),...
'UniformOutput', false);
...避免必须指定 'UniformOutput', false
的一个小技巧是将匿名函数的结果封装在元胞数组中:
output(1, :) = cellfun(@(m) {movmedian(m, 5, 3)}, output(1, :));