Find the value which causes an error from a vector

3 visualizaciones (últimos 30 días)
Christian Berwanger
Christian Berwanger el 18 de Nov. de 2020
Comentada: Christian Berwanger el 18 de Nov. de 2020
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?

Respuestas (1)

Stephan
Stephan el 18 de Nov. de 2020
Editada: Stephan el 18 de Nov. de 2020
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 comentarios
Christian Berwanger
Christian Berwanger el 18 de Nov. de 2020
Editada: Christian Berwanger el 18 de Nov. de 2020
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 el 18 de Nov. de 2020
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

Iniciar sesión para comentar.

Categorías

Más información sobre Testing Frameworks en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by