matlab a function in m-file

Started by
1 comment, last by Brother Bob 17 years, 1 month ago
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?
akira32 編程之家 Yahoohttp://tw.myblog.yahoo.com/akira32-akira32
Advertisement
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
"Voilà! In view, a humble vaudevillian veteran, cast vicariously as both victim and villain by the vicissitudes of Fate. This visage, no mere veneer of vanity, is a vestige of the vox populi, now vacant, vanished. However, this valorous visitation of a bygone vexation stands vivified, and has vowed to vanquish these venal and virulent vermin vanguarding vice and vouchsafing the violently vicious and voracious violation of volition. The only verdict is vengeance; a vendetta held as a votive, not in vain, for the value and veracity of such shall one day vindicate the vigilant and the virtuous. Verily, this vichyssoise of verbiage veers most verbose, so let me simply add that it's my very good honor to meet you and you may call me V.".....V
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