find index of value in array

3 次查看(过去 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