Automatically identify two numbers within an matrix

조회 수: 1 (최근 30일)
Alberto Acri
Alberto Acri 2023년 2월 16일
편집: Antonios Dougalis 2023년 2월 16일
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
Alberto Acri
Alberto Acri 2023년 2월 16일
Definitely ignore numbers smaller than 70.
John D'Errico
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.

댓글을 달려면 로그인하십시오.

채택된 답변

Voss
Voss 2023년 2월 16일
편집: Voss 2023년 2월 16일
matrix = readmatrix('matrix.txt');
matrix_1 = readmatrix('matrix_1.txt');
min_matrix = min(matrix(matrix >= 70))
min_matrix = 174
max_matrix = max(matrix(matrix >= 70))
max_matrix = 199
min_matrix_1 = min(matrix_1(matrix_1 >= 70))
min_matrix_1 = 194
max_matrix_1 = max(matrix_1(matrix_1 >= 70))
max_matrix_1 = 201

추가 답변 (1개)

Mathieu NOE
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

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by