Calling Syntax
The syntax for calling a function using a function handle is the same as that used when calling the function directly. For example, if you call function myFun like this:
[out1, out2, ...] = myFun(in1, in2, ...);
then you would call it using a handle in the same way, but using the handle name instead:
fHandle = @myFun;
[out1, out2, ...] = fHandle(in1, in2, ...);
There is one small difference. If the function being called takes no input arguments, then you must call the function with empty parentheses placed after the handle name. If you use only the handle name, MATLAB just identifies the name of the function:
% This identifies the handle. % This invokes the function.
fHandle = @computer; fHandle = @computer;
fHandle fHandle()
ans = ans =
@computer PCWIN
เรียกไวยากรณ์
ไวยากรณ์สำหรับการเรียกฟังก์ชันใช้จัดการฟังก์ชันจะเหมือนกับที่ใช้เมื่อเรียกฟังก์ชันโดยตรง ตัวอย่างเช่น ถ้าคุณเรียกใช้ฟังก์ชัน myFun นี้:
[out1, out2,...] = myFun (in1, in2,...);
แล้วคุณจะเรียกใช้การจัดการในลักษณะเดียวกัน แต่ใช้ชื่อจัดการแทน:
fHandle = @myFun;
[out1, out2,...] = fHandle (in1, in2,...);
มีความแตกต่างเล็ก ๆ หนึ่ง ถ้าฟังก์ชันถูกเรียกใช้ไม่มีอาร์กิวเมนต์ป้อนเข้า แล้วคุณต้องเรียกใช้ฟังก์ชัน ด้วยวงเล็บว่างเปล่าที่อยู่หลังชื่อหมายเลขอ้างอิง ถ้าคุณใช้เฉพาะชื่อจับ MATLAB เพียงระบุชื่อของฟังก์ชัน:
%นี้ระบุหมายเลขอ้างอิง %นี้เรียกใช้ฟังก์ชัน
fHandle = @computer fHandle = @computer;
() fHandle fHandle
ans = ans =
@computer PCWIN
การแปล กรุณารอสักครู่..

โทรไวยากรณ์
ไวยากรณ์สำหรับการเรียกฟังก์ชั่นการใช้ฟังก์ชั่นจับเป็นเช่นเดียวกับที่ใช้เมื่อเรียกใช้ฟังก์ชันโดยตรง ตัวอย่างเช่นถ้าคุณโทร myFun ฟังก์ชั่นเช่นนี้[OUT1, OUT2 ... ] = myFun (in1, in2, ... ); แล้วคุณจะเรียกมันว่าการใช้การจัดการในลักษณะเดียวกัน แต่ใช้ชื่อที่จับ แทน: fHandle = @ myFun; [OUT1, OUT2 ... ] = fHandle (in1, in2, ... ); มีหนึ่งความแตกต่างเล็ก ๆ ถ้าฟังก์ชันถูกเรียกว่าใช้เวลาไม่ขัดแย้งเข้าแล้วคุณจะต้องเรียกใช้ฟังก์ชันที่มีวงเล็บว่างอยู่หลังชื่อที่จับ ถ้าคุณใช้เพียงชื่อจับ MATLAB เพียงแค่ระบุชื่อของฟังก์ชัน: % นี้จะระบุการจัดการ % นี้จะเรียกฟังก์ชั่นfHandle = @ คอมพิวเตอร์ fHandle = @ คอมพิวเตอร์fHandle fHandle () ans = ans = @ คอมพิวเตอร์ PCWIN
การแปล กรุณารอสักครู่..

เรียกไวยากรณ์ไวยากรณ์สำหรับการเรียกใช้ฟังก์ชันการใช้ฟังก์ชันจัดการเป็นแบบเดียวกับที่ใช้เมื่อเรียกฟังก์ชันโดยตรง ตัวอย่างเช่น ถ้าคุณเรียกฟังก์ชัน myfun แบบนี้
[ out1 out2 , . . . ] = ( 1 myfun ” , , . . . ) ;
แล้วคุณจะเรียกใช้จัดการในวิธีเดียวกัน แต่ใช้ชื่อจัดการแทน :
fhandle = @ myfun out1 out2 [ ;
, , . . . . . . . ] = ( 1 fhandle ” , ,
. . . . . . . )มีความแตกต่างเล็ก ๆคนหนึ่ง ถ้าฟังก์ชันที่ถูกเรียกใช้อาร์กิวเมนต์ใส่แล้วคุณจะต้องเรียกฟังก์ชันด้วยเปล่า ) อยู่หลังชื่อจัดการ ถ้าคุณเพียงใช้ชื่อจับ , Matlab ก็ระบุชื่อของฟังก์ชัน :
% นี้จะระบุจัดการ นี้จะเรียกฟังก์ชัน
fhandle = @ = @ คอมพิวเตอร์คอมพิวเตอร์ fhandle ;
fhandle ans = =
fhandle() ans@ pcwin คอมพิวเตอร์
การแปล กรุณารอสักครู่..
