필터 지우기
필터 지우기

How to find same values in an array and their index

조회 수: 2 (최근 30일)
University
University 2023년 11월 13일
댓글: University 2023년 11월 13일
Hi,
I have array with some repeated values. I have 1e-6 repeatedly. How can I have find all the values and their corresponding index?

답변 (1개)

Dyuman Joshi
Dyuman Joshi 2023년 11월 13일
이동: Dyuman Joshi 2023년 11월 13일
arr = load('array.mat')
arr = struct with fields:
yintercept: [100×2 double]
mat = arr.yintercept
mat = 100×2
1.0e-06 * 1.0000 0 1.0000 0 1.0000 0 0.1280 1.0000 0.1300 1.0000 0.1319 1.0000 0.1338 1.0000 0.1357 1.0000 0.1375 1.0000 0.1393 1.0000
val = 1e-6;
%As you are dealing with floating point numbers, use tolerance to compare
[r, c] = find(abs(mat-val)<1e-9)
r = 100×1
1 2 3 18 25 39 41 42 43 44
c = 100×1
1 1 1 1 1 1 1 1 1 1
  댓글 수: 1
University
University 2023년 11월 13일
Thanks for your response. Sorry I attached a wrong array. I have 1e-6 repeatedly. How can I have find all the values and their corresponding index?

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

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by