[英]Matlab Function and Input
function area = traparea(a,b,h)
% traparea(a,b,h) Computes the area of a trapezoid given
% the dimensions a, b and h, where a and b
% are the lengths of the parallel sides and
% h is the distance between these sides
% Compute the area, but suppress printing of the result
area = 0.5*(a+b)*h;
這只是一個例子。 我想知道如何在一個單獨的.m文件中聲明假設a = 5,b = 4,h = 8的值,並使用.in語句將其調用到原始函數(即traparea)中? 例如,在這樣的a = 5中,請幫助
據我了解,您想創建一個腳本文件。 創建一個名為“ myscript.m”的文件名(選擇您喜歡的任何名稱),並將其放置在與“ traparea.m”所在的文件夾中。 然后,在文件“ myscript.m”中放入以下內容:
a = 5;
b = 4;
h = 8;
result = traparea(a,b,h) % this is one way to show the result
fprintf('my result is %f\n', result); % this is another way to display the result
創建兩個文件“ myscript.m”和“ traparea.m”后,只需在命令行中鍵入“ myscript”。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.