how to read and change entries in a large array
1 次查看(过去 30 天)
显示 更早的评论
I have a 842x650, i want to read through every entry, check its value and if its under a certain value change it to zero. Any help would be amazing !!
0 个评论
采纳的回答
KL
2018-2-26
It's easier to answer with an example. Let's say we have a matrix of 5x5 with random numbers and you want to find the elements that are between 0.5 and 0.75 and then make it to zero.
A = rand(5,5)
ind = A>=0.5 & A<=0.75;
A(ind) = 0;
A
and now an example result is (before and after),
A =
0.8001 0.1455 0.1450 0.4018 0.2400
0.4314 0.1361 0.8530 0.0760 0.4173
0.9106 0.8693 0.6221 0.2399 0.0497
0.1818 0.5797 0.3510 0.1233 0.9027
0.2638 0.5499 0.5132 0.1839 0.9448
A =
0.8001 0.1455 0.1450 0.4018 0.2400
0.4314 0.1361 0.8530 0.0760 0.4173
0.9106 0.8693 0 0.2399 0.0497
0.1818 0 0.3510 0.1233 0.9027
0.2638 0 0 0.1839 0.9448
1 个评论
KL
2018-2-26
I'd also recommend reading a bit about floating point numbers. Various threads with extensive explanations exist, probably start with this one: https://www.mathworks.com/matlabcentral/answers/57444-faq-why-is-0-3-0-2-0-1-not-equal-to-zero
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!