I try reduce my matrix a single value for my input or a call a value

1 次查看(过去 30 天)
Hello. I have matrix and I try the use the value in the matix for my input. I wanna the take this value as a integer. Also all values are integer in my matix. How can I take a value for my input in matrix. Thanks a lot.
  1 个评论
David Hill
David Hill 2022-11-29
Just index into your matrix. You can use linear indexing or row,column
m=randi(100,10)
m = 10×10
92 29 95 94 6 93 46 52 9 21 74 5 96 84 20 43 75 21 73 86 32 60 4 24 35 3 21 95 42 77 17 54 70 84 80 53 65 97 50 39 25 82 44 15 58 70 28 93 84 29 94 2 73 20 19 51 15 44 9 44 65 44 5 76 57 78 49 78 74 22 13 60 100 62 86 17 10 55 36 86 28 58 45 98 8 50 76 62 63 31 85 10 72 9 22 16 20 85 52 26
m(15)
ans = 82
m(5,2)
ans = 82

请先登录,再进行评论。

回答(1 个)

Vilém Frynta
Vilém Frynta 2022-11-29
You can call value in vector by specifying it's position.
mtx = [1, 2; 3, 4; 5, 6]
mtx = 3×2
1 2 3 4 5 6
Now you have to write matrix name (in my example it's "mtx") and write position. First row number, then column number.
mtx(1,2) % number in 1st row, 2nd column
ans = 2
mtx(3,1) % number in 3rd row, 1st column
ans = 5
Is this what you asked? Feel free to ask more. I'm not 100% sure I understood your question.

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

标签

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by