Error assignment of elements with ode15s

1 回表示 (過去 30 日間)
Jeanine
Jeanine 2013 年 3 月 16 日
I get the error "??? In an assignment A(I) = B, the number of elements in B and I must be the same."
I have tried debugging and evaluating the sizes of the left and right hand side of the culprit line but they are the same size (this is true for all values of t). When I evaluate the line in my workspace I do not have a problem. Below is the context of the problem:
Does anyone know why I am getting this error?
function dc=prob(t,c,A)
%system of odes with experimental data (A) passed to function
%odes are evaluated using ode15s at prescribed times from experimental data
dc=zeros(3,1);
V=2;
K=3;
km=4;
t_exp=xlsread('RawData.xlsx','raw data','E8:E47'); %experimental times
ind=find(t_exp==t); %find the time point being evaluated at this point
B=A(ind); %locate the experimental data value corresponding to time point
dc(1)=km*c(3);
dc(2)=(V*B/(K + B ))*(c(1)/(km + c(1))); %THIS IS THE LINE THAT CAUSES THE ERROR
dc(3)=V+c(2);

採用された回答

Walter Roberson
Walter Roberson 2013 年 3 月 17 日
ind=find(t_exp==t) is going to return ind as a logical vector that could have 0, 1, or multiple values set. Usually 0. If it does not happen to have exactly one true value, then B will not have exactly one value, and then the expression for dc(2) will be trying to store 0 or more-than-one values into a single scalar location dc(2)
  3 件のコメント
Walter Roberson
Walter Roberson 2013 年 3 月 17 日
At the command line, give the command
dbstop if error
and run the program. When it stops due to the error, examine the values then.
Jeanine
Jeanine 2013 年 3 月 26 日
Thanks! It was producing an empty matrix at some times.

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

その他の回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 3 月 16 日
編集済み: Azzi Abdelmalek 2013 年 3 月 16 日
A bracket is missing, it should be
dc(2)=(V*B/(K + B ))*(c(1)/(km + c(1)))
  1 件のコメント
Jeanine
Jeanine 2013 年 3 月 17 日
Oops, that was a typo - it's not what is causing the error though. Thanks for the response.

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

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by