Matrix Element Transfer from one matrix to another
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have a matrix of 10X10. I want to select elements of this matrix and put them in an N X 2 Matrix. As example, if one of the selected elements of the 10X10 matrix is at 10, 12 I want this 10,12 to be transferred to the N X 2 matrix. Hence, basically the question I am asking is how to transfer position i.e row,col of a matrix from one to the other.
0 commentaires
Réponses (2)
James Tursa
le 6 Oct 2016
I am not quite clear what you are asking. Is it something like this?
>> A = reshape(1:100,10,10) % <-- test data
A =
1 11 21 31 41 51 61 71 81 91
2 12 22 32 42 52 62 72 82 92
3 13 23 33 43 53 63 73 83 93
4 14 24 34 44 54 64 74 84 94
5 15 25 35 45 55 65 75 85 95
6 16 26 36 46 56 66 76 86 96
7 17 27 37 47 57 67 77 87 97
8 18 28 38 48 58 68 78 88 98
9 19 29 39 49 59 69 79 89 99
10 20 30 40 50 60 70 80 90 100
>> [row,col] = find(A==47) % <-- pick off row & column of location of 47
row =
7
col =
5
>> B(1,1:2) = [row,col] % Stuff the row & col into the 1st row of B
B =
7 5
>> [row,col] = find(A==59) % <-- pick off row & column of location of 59
row =
9
col =
6
>> B(2,1:2) = [row,col] % Stuff the row & col into the 2nd row of B
B =
7 5
9 6
3 commentaires
James Tursa
le 6 Oct 2016
Does this do what you want?
>> A = reshape(randperm(25),5,5)
A =
17 2 24 14 8
1 23 16 10 4
11 12 20 18 15
6 9 22 13 5
25 3 21 19 7
>> [row,col] = find(A<10); % <-- find where A is less than 10
>> result = [row col]
result =
2 1
4 1
1 2
4 2
5 2
1 5
2 5
4 5
5 5
Star Strider
le 6 Oct 2016
If I understand what you want, the find function will do exactly that.
Example:
M = randi(9, 10); % Create Matrix
[row,col] = find(M == 3); % Return Rows & Cols Of All ‘3’ Values
6 commentaires
Star Strider
le 6 Oct 2016
Dijkstra's algorithm may be what you’re looking for. I’ve no experience with it, nor coding any optimal-path problems.
Voir également
Catégories
En savoir plus sur Matrix Indexing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!