フィルターのクリア

Unable to call my function and get an error

1 回表示 (過去 30 日間)
Muhammad Choudhury
Muhammad Choudhury 2022 年 2 月 4 日
コメント済み: Davide Masiello 2022 年 2 月 4 日
function h = fplothFUNC(d,Kp,A,t)
%the function is used to plot the following equation:
% h*(t)=(d/Kp)*(1-exp(-(Kp/A)*t))
% call for function:
% h = fplothFUNC(1,[0.2 2 6 15 55 105],2,0:0.1:10)
LK=length(Kp);
Lt=length(t);
h=zeros(LK,Lt); %create a matrix of zeros for LK AND Lt columns
for i=1:LK
h(i,:)= (d/Kp(i))*(1-exp(-(Kp(i)/A)*t));
end
end
semilogy(t,h); xlabel('time (hours)'); ylabel('height difference (m)')
h = fplothFUNC(1,[0.2 2 6 15 55 105],2,0:0.1:10)
i get an error saying:
Error: File: fplothFUNC.m Line: 16 Column: 1
This statement is not inside any function.
(It follows the END that terminates the definition of the function "fplothFUNC".)

採用された回答

Davide Masiello
Davide Masiello 2022 年 2 月 4 日
d = 1;
t = 0:0.1:10;
Kp = [0.2 2 6 15 55 105];
A = 2;
h = fplothFUNC(d,Kp,A,t);
semilogy(t,h); xlabel('time (hours)'); ylabel('height difference (m)')
function h = fplothFUNC(d,Kp,A,t)
LK=length(Kp);
Lt=length(t);
h=zeros(LK,Lt); %create a matrix of zeros for LK AND Lt columns
for i=1:LK
h(i,:)= (d/Kp(i))*(1-exp(-(Kp(i)/A)*t));
end
end
Result:
  2 件のコメント
Muhammad Choudhury
Muhammad Choudhury 2022 年 2 月 4 日
thanks but why can it not be in this form?:
h = fplothFUNC(1,[0.2 2 6 15 55 105],2,0:0.1:10)
Davide Masiello
Davide Masiello 2022 年 2 月 4 日
It can, I was just ordering the way I usually do.
The problem with your script was that the function was defined before the command calling it, and that is not how matlab works.
I hope this clarifies things. Please consider accepting the answer if it solved your issue, cheers!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by