Find the value which causes an error from a vector
1 回表示 (過去 30 日間)
古いコメントを表示
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?
0 件のコメント
回答 (1 件)
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Testing Frameworks についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!