¥H¤U¤¶²Ð¤@Ó²³æªº C µ{¦¡½X¡A¥¦¥i±N¤@Ó¿é¤J¯Â¶q¡]¸ê®Æ«¬ºA¬° double¡^¼¥H 2¡A¦¹µ{¦¡½X¤w¤º«Ø¦b MATLAB ¥úºÐ¤¤¡A¨ä¦ì¸m¬°¡G
{MATLAB root}\extern\examples\refbook\timestwo.c
§@ªÌ¤w¦bìµ{¦¡½X¥[¤W¸Ô²Óªº¤¤¤åµù¸Ñ¡A¨Ã§ï¦W¬° scalarx2.c¡A§ó§ï«áªº C µ{¦¡½X¤º®e¦C¥X¦p¤U¡G
¤W± scalarx2.c µ{¦¡½X§¡¤vªþ¤WÂ×´Iµù¸Ñ¡A¬G¦b¦¹¤£¦A»¡©ú¡C±µµÛ¦b MATLAB ¤¤¡A©I¥s C ½s;¹¹ï scalarx2.c µ{¦¡½X¶i¦æ½sͦp¤U¡G
>> mex scalarx2.c
½sͧ¹«á¡A½T»{¥i°õ¦æÀɬO§_¦s¦b¡A¥i¿é¤J¦p¤U¡G
>> which scalarx2
D:\matlabBook\MATLABµ{¦¡³]p¡G¶i¶¥½g\03-À³¥Îµ{¦¡¤¶±\scalarx2.mexw64
±µµÛ§Y¥i¶i¦æ¦U¶µ´ú¸Õ¡A¥i¿é¤J¦p¤U¡G
>> scalarx2(8.5)
ans =
17
>> scalarx2('String input')
??? Input must be a scalar.
>> scalarx2([1 2 3])
??? Input must be a scalar.
Y¦P®É¦³ scalarx2.m ¤Î scalarx2.mexw64 ¦s¦b©ó¦P¤@¥Ø¿ý¤U¡AMATLAB ·|¿ï¥Î scalarx2.mexw64 ÀɨӰõ¦æ¡A¦Ó©¿²¤ scalarx2.m¡C¦ý¬O¦pªG¿é¤J¡uhelp scalarx2¡v¡AMATLAB ·|¦C¥X scalarx2.m ªº½u¤W»²§U»¡©ú¡]¦]¬°µLªk¦b scalarx2.c ¤Î scalarx2.mexw64 Â\¸m¬ÛÃöªº½u¤W»²§U»¡©ú¡^¡C´«¥y¸Ü»¡¡A¦³Ãö scalarx2.mexw64 ªº½u¤W»²§U»¡©ú¡A´N¥²¶·¸m©ó scalarx2.m ¤§¤º¡C¨Ò¦p§ÚÌ¥i¥HÅã¥Ü scalarx2.m ªº¤º®e¡G
>> type scalarx2.m
function out = scalarx2(in)
% SCALARX2 A scalar version of "times two".
% This serves as an example of putting on-line help in an
% M-file, but the actual program body is in another MEX-file
% with the same major file name.
©ÎÅã¥Ü scalarx2.m ªº»¡©ú¡G
>> help scalarx2
SCALARX2 A scalar version of "times two".
This serves as an example of putting on-line help in an
M-file, but the actual program body is in another MEX-file
with the same major file name.
¦ýYn¶i¦æ°õ¦æ®É¡A§ÚÌ¥i¥H¨Ï¥Î which «ü¥O¨ÓÅã¥Ü scalarx2 ©Ò¹ïÀ³ªº°õ¦æÀɮ׬O MEX ÀɮצӤ£¬O M ÀɮסG
>> which scalarx2
D:\matlabBook\MATLABµ{¦¡³]p¡G¶i¶¥½g\03-À³¥Îµ{¦¡¤¶±\scalarx2.mexw64
MATLABµ{¦¡³]p¡G¶i¶¥½g