Looping over function string arguments

The problem is:
%%%%%%%%%%%%%%%%%%%%%%%%%%%This works fine %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%interpolation='bicubic';
interpolation='bilinear';
for scale=1:4
for image_idx={'01', '02', '03'}
img_name = strjoin(cellstr(['E:\', image_idx, '.tiff']));
Iin = imread(img_name);
...
Iout = imresize(Iin, scale, interpolation);
...
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%This does not %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for interpolation={'bilinear', 'bicubic'}
for scale=1:4
for image_idx={'01', '02', '03'}
...
Iout = imresize(Iin, scale, interpolation);
...
end
end
end
Second case throws an exception:
Index exceeds matrix dimensions.
Error in imresize>parseMethodArg (line 432)
kernel_width = method{2};
Error in imresize>parseInputs (line 252)
[params.kernel, params.kernel_width, params.antialiasing] = ...
Error in imresize (line 141)
params = parseInputs(varargin{:});
Error in test_algorithm (line 25)
Ic = imresize(Ic, scale, interpolation);

 採用された回答

David Sanchez
David Sanchez 2014 年 6 月 17 日

1 投票

In the second method you are passing a cell array as input argument.
Try this:
interpolation={'bilinear', 'bicubic'};
for k=1:numel(interpolation)
for scale=1:4
for image_idx={'01', '02', '03'}
...
Iout = imresize(Iin, scale, interpolation{k});
...
end
end
end

3 件のコメント

Egor
Egor 2014 年 6 月 17 日
編集済み: Egor 2014 年 6 月 17 日
No errors so far.
Why does this part work as expected so?
for image_idx={'01', '02', '03'}
img_name = strjoin(cellstr(['E:\', image_idx, '.tiff']));
It is iterating over "filelist" without additional indexing, isn't it?
David Sanchez
David Sanchez 2014 年 6 月 17 日
They are different command/functions.
strjoin works fine with cell arrays as input arguments.
For any other function, the input arguments has to be a string.
Egor
Egor 2014 年 6 月 17 日
Yeah, just 've got it by myself.
Thanks for the help!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

質問済み:

2014 年 6 月 17 日

編集済み:

2014 年 6 月 17 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by