parvector not able to pass

3 ビュー (過去 30 日間)
Devyani
Devyani 2014 年 10 月 18 日
コメント済み: Star Strider 2014 年 10 月 18 日
I have created this simple functon file to call other functions.
function [conc ] = getconc( expConditions,parVector )
c(1) = expConditions(1);
c(2) = expConditions(2);
c(3) = expConditions(3);
[t cout1] = ode45('model1',[0:1:9],expConditions);
[t cout2] = ode45('model2',[0:1:9],expConditions);
[t cout3] = ode45('model3',[0:1:9],expConditions);
[t cout4] = ode45('model4',[0:1:9],expConditions);
[t cout5] = ode45('model5',[0:1:9],expConditions);
[t cout6] = ode45('model6',[0:1:9],expConditions);
[t cout7] = ode45('model7',[0:1:9],expConditions);
[t cout8] = ode45('model8',[0:1:9],expConditions);
[t cout9] = ode45('model9n',[0:1:9],expConditions);
[t cout10] = ode45('model10',[0:1:9],expConditions);
conc=[cout1(:,1) cout2(:,2) cout3(:,1) cout4(:,2) cout5(:,1) cout6(:,2) cout7(:,1) cout8(:,2) cout9(:,1) cout10(:,2)];
end I give inputs for expConditions and parVector as [1 1 1 1 1 1 1 1 1 1] and [5 5 50]. I am getting the following error :
Attempted to access parVector(1); index out of bounds because numel(parVector)=0.
The parVector input is required in my function files which i am calling for ode45solver. example for ne model function file is as follows
function [fdot] = model1(t,c,parVector )
r=-parVector(1);
fdot(1)=r;
fdot(2)=r;
fdot(3)=0;
fdot=fdot'
I am calling function as follows:
>> parVector=[1 1 1 1 1 1 1 1 1 1];
>> expConditions=[5 5 50];
>> getconc(parVector,expConditions);

採用された回答

Star Strider
Star Strider 2014 年 10 月 18 日
It is easiest to use the ‘anonymous function’ construction to pass ‘parVector’ to your ODE functions.
For example in ‘getconc’:
[t cout1] = ode45(@(t,c) model1(t,c,parVector ),[0:1:9],expConditions);
See if that does what you want. If it does, change your other ode45 calls to the same syntax.
  4 件のコメント
Devyani
Devyani 2014 年 10 月 18 日
yup its working thanks!
Star Strider
Star Strider 2014 年 10 月 18 日
My pleasure!

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

その他の回答 (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