find a values in matrix
1 次查看(过去 30 天)
显示 更早的评论
I have matrix H[ 0 2.3926
2.3926 0]
I want to find value in matrix H, 2.3926 and store it in a variable A
0 个评论
采纳的回答
Azzi Abdelmalek
2013-11-23
Maybe you are looking for the location
H=[ 0 2.3926
2.3926 0]
[ii,jj]=find(H==2.3926)
0 个评论
更多回答(1 个)
dpb
2013-11-23
编辑:dpb
2013-11-23
val=2.3926;
A=H(abs(H-val)<1.e-5);
NB the "fuzzy" comparison to avoid FP precision problems
2 个评论
dpb
2013-11-23
编辑:dpb
2013-11-24
Not sure what the question is, precisely. Of course the comparison can be any value or range of values. There are times when owing to FP rounding find(x==val) won't return what is naively expected.
You can always write
A=H(H==2.3926);
and for some cases you'll find joy, in others "not so much"
Look up "logical addressing" in the documentation for more detail of how this works.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Fuzzy Logic Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!