find index of value in array

조회 수: 2 (최근 30일)
Elif KORKMAZ
Elif KORKMAZ 2021년 10월 30일
편집: DGM 2021년 10월 30일
hello, how can I find which numbers in a matrix are less than x and then print another number instead of the number I found?

답변 (1개)

DGM
DGM 2021년 10월 30일
편집: DGM 2021년 10월 30일
A = randi(99,10,10) % test array
A = 10×10
11 29 88 59 64 59 20 49 53 65 60 75 47 68 47 69 2 43 13 46 37 70 50 17 82 37 64 72 86 75 33 13 2 76 57 66 74 76 10 99 53 9 79 5 62 83 8 46 94 83 47 58 88 62 79 36 5 56 57 53 88 4 19 64 49 53 22 25 98 90 18 79 23 97 34 47 41 42 38 53 51 93 3 94 78 45 32 5 39 14 44 16 58 26 77 94 8 89 50 34
x = 30;
lessthanx = A(A<x) % all the numbers in A that are < x
lessthanx = 25×1
11 18 29 13 9 4 16 2 19 23
fprintf('%d',randi(1000,1,1)) % "print another number instead of the number I found"
463

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by