If values are approxximately the same plot one function, if not plot two

Hello, I have a two vectors with calculation results. Has someone of you an idea how can I compare results of this two vectors and if all values are similar (ex. ~0.5 for each value) matlab will plot one function (plot(vec1,x)) and if difference is greater two functions (plot(vec1,x) and plot(vec2,x))?
Thank you

 採用された回答

dpb
dpb 2015 年 9 月 20 日
編集済み: dpb 2015 年 9 月 21 日
Presuming the 'all' in "if all values are similar" means a pointwise comparison between the two vectors of same length, then
if all(abs(v1-v2)<delta) % set delta as desired
plot(x,mean([v1 v2]) % use average of the two instead of just one
else
plot(x [v1 v2])
end
I've also assumed v1;v2 are column vectors and that x is the independent variable. Altho I suppose, mayhaps it could be t'other way 'round in which case reverse the order of the arguments to plot

4 件のコメント

Matthew Worker
Matthew Worker 2015 年 9 月 21 日
Your all assumptions are correct. Unfortunately I am not able to find delta that will work as I want. I try very small and also bigger values but its still showing plots wrong (sometimes even if both function looks identical it plots both of them)
Maybe there is another way?
Thorsten
Thorsten 2015 年 9 月 21 日
The parentheses were wrong. Must be
all(abs(v1 - v2) < delta)
Matthew Worker
Matthew Worker 2015 年 9 月 21 日
thank you :)
dpb
dpb 2015 年 9 月 21 日
Yup, sorry..."air code" is prone to typos...

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMathematics についてさらに検索

製品

タグ

質問済み:

2015 年 9 月 20 日

コメント済み:

dpb
2015 年 9 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by