calling a function in a different script.

6 ビュー (過去 30 日間)
Prakriti Biswas
Prakriti Biswas 2020 年 9 月 11 日
回答済み: Asad (Mehrzad) Khoddam 2020 年 9 月 11 日
Hi,
I'm trying to write a MATLAB code where I call a function with 3 parameters, into another script file and integrating the function I had defined earlier.
I defined my function as:
classdef trialchegg1
methods
function v=velocity(r,r0,n)
v=r.*(1-r/r0).^(1/n);
end
end
end
And the other script contains:
vmax=1.5;
r0=input('Enter the value of r0');
n=input('Enter the value for n');
y=trialchegg1.velocity(r,r0,n)
integral=quad('y',0,r0)
ave_velocity = (2*vmax/(r0^2))*integral
I am getting the error:
Unrecognized function or variable 'r'.
Error in trialchegg (line 4)
y=trialchegg1.velocity(r,r0,n)
I am trying to integrate with respect to r in the other script, using quad.
Can someone help me out?

回答 (1 件)

Asad (Mehrzad) Khoddam
Asad (Mehrzad) Khoddam 2020 年 9 月 11 日
One solution is that you can use this command at the top of the files that use 'r'
global r;
Just after function definition

カテゴリ

Help Center および File ExchangeSoftware Development Tools についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by