2
votes

I have a directory with n m-files (cI_0001.m, cI_0002.m, ...) defining each a complex function that should be used for image transformation with imtransform the kind of:

conformal = maketform('custom', 2, 2, [], @cI_0001, []);
T = imtransform(C, conformal, ...);

In the simplest case I want a loop that apply imtransform to an image C for all the given functions. So I made a cell array for the directory with the m-file names without extension (m_name_list) and I think I need a kind of a pointer in maketform() to the elements in m_name_list. How can this be correctly formulated?

for i=1:n
   conformal = maketform('custom', 2, 2, [], @pointer_to_the_ith_element_in_m_name_list, []);
   T = imtransform(C, conformal, ...);
   imwrite(T, ...);
end

I saw the proposal with run in How to set function arguments to execute different set of m-files but this seems not working with the function calling in maketform().

EDIT: I include a list with function names + extension to which pointers could be made (possible extended to a list of paths+names):

m_dir_entries = dir(strcat(CM_inverse_folder_path, '*.m'));
m_name_list   = cell(1,length(m_dir_entries));
for k=1:length(m_dir_entries)
  m_name_list{k} = m_dir_entries(k).name; 
end
1

1 Answers

1
votes

You can use str2func to create a function handle to each of the .m files

% Add the folder to your path
addpath(CM_inverse_folder_path)

function_list = {'cI_0001.m', 'cI_0002.m'};

% Remove the extensions
[~, function_list] = cellfun(@fileparts, function_list, 'UniformOutput', false);

for k = 1:n
    func = str2func(function_list{k});
    conformal = maketform('custom', 2, 2, [], func, []);
    T = imtransform(C, conformal, ...);
    imwrite(T, ...);
end

% Remove the folder from the path
rmpath(CM_inverse_folder_path)