Automatically identify two numbers within an matrix
1 次查看(过去 30 天)
显示 更早的评论
Is there any way to automatically locate two numbers within a matrix?
For example:
- for the file "matrix_1.txt" I am interested in identifying the following numbers 194 (min) and 201 (max)
- for the file "matrix.txt" I am interested in identifying the following numbers 175 (min) and 199 (max)
So I am interested in a code that can identify these numbers without me knowing them. Like the max/min command that identifies the max/min within a matrix for example.
5 个评论
John D'Errico
2023-2-16
You are not telling us enough information. You want to find a number, like the max and min, But they may not be the smallest or largest numbers in the matrix. In fact, they are not even close to that.
So apparently you know what you want, but cannot describe it. And the matrices you show are not at all clear in how you would decide on those specific values.
采纳的回答
更多回答(1 个)
Mathieu NOE
2023-2-16
编辑:Mathieu NOE
2023-2-16
hello Alberto
welcome back !
here a demo for the 'matrix.txt' case
the other one is basically the same , simply change the min / max values
M = readmatrix('matrix.txt');
value_min = 175;
value_max = 199;
ind = find(M>=value_min & M<=value_max); % linear index
M(ind) % show the M values (to double check)
[r,c] = ind2sub(size(M),ind) % show corresponding row / col indexes
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!