MATLAB Answers

iam unable to call function in for loop?

3 views (last 30 days)
barath V
barath V on 6 Feb 2020
Commented: barath V on 6 Feb 2020
this is the error iam getting
The file name or URL argument must be a character vector or string scalar.
Error in imread (line 342)
[source, fmt_s, extraArgs, was_cached_fmt_used] = parse_inputs(cached_fmt, varargin{:});
im = double(imread(image))
clear all;
D = 'C:\Users\PRL\Desktop\barathfocus\for-matlab-testonly';
S = dir(fullfile(D,'*.tif')); % pattern to match filenames.
for k = 1:numel(S)
F = fullfile(D,S(k).name);
I = double(imread(F));
a = bodekke(I);
function[addition] = bodekke(image)
im = double(imread(image))
bd = [-1 0 1]
cbd = conv2(im,bd)
squaredcbd = cbd.^2
addition = sum(squaredcbd(:))
barath V
barath V on 6 Feb 2020
yes,is working thanks bhaskar.
but i dont understand why it works.
i have passed the image to variable I.
and i call the function with image I it should work.
why it is working if i call by using its name

Sign in to comment.

Accepted Answer

Shunichi Kusano
Shunichi Kusano on 6 Feb 2020
The argument for imread must be file location. "image" in the function is an array.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!