Matching two numbers using only 2 decimal points
古いコメントを表示
Hi,
I have 2 numbers that I want to match in my program and if these don't match I want to receive an error message. The two numbers that I want to match should match only up to the first two decimal points. For example,
A=3.82 and B=3.829 should match since 3.82 is common. On the other hand, A=3.82 and B=3.8 don't match .How can I match A and B?
採用された回答
その他の回答 (1 件)
Robert Cumming
2012 年 1 月 8 日
compare = @(n1,n2,n_dcp) round(n1*10^n_dcp)==round(n2*10^n_dcp);
>> compare(1.23,1.234,2)
ans =
1
>> compare(1.23,1.2,2)
ans =
0
1 件のコメント
Anu
2024 年 4 月 16 日
'compare' function requires one of the following Toolbox:
1. System Identification Toolbox
2. Model Predictive Control Toolbox
3. Predictive Maintenance Toolbox
Is there any alternative method
カテゴリ
ヘルプ センター および File Exchange で Deep Learning Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!