フィルターのクリア

Find the value which causes an error from a vector

1 回表示 (過去 30 日間)
Christian Berwanger
Christian Berwanger 2020 年 11 月 18 日
コメント済み: Christian Berwanger 2020 年 11 月 18 日
Hello,
I do have the following code:
function [test] = func(T)
T_grenz=112;
if T>=T_grenz
svol = 50*T;
elseif T<T_grenz
svol = 100*T;
end
if svol==0
svol = 0.001;
elseif isemtpy(svol)
error("svol is empty at T="); %I want to add this error message correctly
end
test=1/svol;
This matlab script is used by a simulation software. The software calls the matlab function with like a 1x10000 vector and expects a 1x10000 vector as return value.
While running this for some reason matlab gets the error that svol is not defined. However I think in every case svol should have a value. Now I want to reproduce the error. How can I get exact values of my vector T to reproduce the bug. I do not want the whole vector. Just the one value that cause the error. Can I do this with vectors? Or do I have to write the for loop manually to iterate through the vector?

回答 (1 件)

Stephan
Stephan 2020 年 11 月 18 日
編集済み: Stephan 2020 年 11 月 18 日
This works with logical indexing, therefore avoids the if / else logic and should ensure that you do not need any error messages:
function test = func(T)
T_grenz=112;
[r,c] = size(T);
svol = zeros(r,c);
svol(T>=T_grenz) = 50*T(T>T_grenz);
svol(T<T_grenz) = 100*T(T<T_grenz);
svol(svol==0) = 0.001;
test=1./svol;
end
  5 件のコメント
Christian Berwanger
Christian Berwanger 2020 年 11 月 18 日
編集済み: Christian Berwanger 2020 年 11 月 18 日
Ok. One of my problems is that I wanted to deliver a minimal working example of the error and I might have oversimplified it.
svol is actually dependend on a lot of parameters which are defined before. So my function looks roughly more like:
function test = func(T,dT,p)
q=abs(dT);
if q==0:
q=0.1;
end
A = 100+20.*log(q)-0.01*p
Bm = 0.58-0.0003*p+0.00003*p*p
Bs = 0.58-0.0001*p+0.000019*p*p
C = 100.*exp(-0.0023*p)
T_grenz=100+0.1.*log(q)-0.02.*p;
[r,c] = size(T);
svol = zeros(r,c);
svol(T>=T_grenz) = A(T>=T_grenz)+Bm(T>=T_grenz).*T(T>=T_grenz)+0;
svol(T<T_grenz) = A(T<T_grenz)+Bs(T<T_grenz).*T(T<T_grenz)+C(T<T_grenz).*p(T<T_grenz);
svol(svol==0) = 0.001;
test=1./svol;
end
I hope that I did that right.
I use Comsol Multiphysics for my simulation. In Comsol the matlab function is called with roughly 10.000x1 vectors as input parameters and expects a 10.000x1 output vector.
Now. When I create a small vector for myself to test the matlab function I get no errors and I get a result. However. When using Comsol I get an error. Thats why I want to get the error causing vector (or input parameter) which matlab gets from comsol.
Christian Berwanger
Christian Berwanger 2020 年 11 月 18 日
And I use the debugger. But nothing goes wrong in my test. Comsol uses the matlab server, where breakpoints doesn't work. Thats why I want to get the error causing data from comsol, so I can run them with the debugger

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

カテゴリ

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

タグ

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by