matlab a function in m-file
I write a function called improd in m-file(bb.m).
% in bb.m file
function [ p, pmax, pmin ,pn ] = improd ( f, g )
% help22
fd=double (f);
gd=double (g);
p=fd.*gd;
pmax=max(p(:));
pmin=min(p(:));
pn = mat2gray(p);
But when I call improd function,it appears the error about Undefined function improd.
>> f=[1 2 ; 3 4];
>> g=[1 2 ; 2 1];
>> improd(f,g);
??? Undefined command/function 'improd'.
How do I let matlan know that I have declare a fuction in m-file and I want to use the function?
MatLab will look in the currently directory as well as its search path to find the function. Also note that your file has to have the same name as the function, so rename your file to improd.m
Quote:Original post by joanusdmentia
Also note that your file has to have the same name as the function, so rename your file to improd.m
Although good practice, it's not required. If the file name and function name are different, the file name takes precedence. So in OP's case, he could have called his function by typing bb(f,g), since bb is the name of the file.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement