How do I return the indexed values unsorted, in the original order in which they appear in a vector?
조회 수: 1 (최근 30일)
이전 댓글 표시
What I'm trying to accomplish seems like it should be much easier, however I acknowledge that I am not proficient at all and am probably misunderstanding the utlity of this indexing.
There's a couple things I am trying to see if I can resolve:
1) radius_gl ( as shown below is 18 x3) which is not allowing the return of indexed values beyond the limit of 18 even though gamt/lamt have repeat values.
a) Is there a way around this?
2) r1 and r2 was previously returning only 12 or 11 indexed values; this was not the right because 20 values should have been returned, and they were in a sorted order
This is the current code:
75 15 25 % col_1 = G; col_2 = L; col_3 = radii;
77 17 25
79 19 50
81 21 50
83 23 75
85 25 75
87 27 100
89 29 100
91 31 125
93 33 125
95 35 150
97 37 150
99 39 175
101 41 175
103 43 200
105 45 200
107 47 225
109 49 225
% heres a snippet of the lamt (20 x 1); gamt is structured the same but has
% different range of numbers
47
43
21
43
17
17
47
45
43
19
33
29
idx_gamt = find(ismember(gamt, radius_gl(:, 1),"rows"));
idx_lamt = find(ismember(lamt, radius_gl(:, 2), "rows"));
r1 = radius_gl(idx_gamt, 3);
r2 = radius_gl(idx_lamt, 3);
댓글 수: 0
채택된 답변
Voss
2024년 1월 7일
편집: Voss
2024년 1월 7일
radius_gl = [75 15 25 % col_1 = G; col_2 = L; col_3 = radii;
77 17 25
79 19 50
81 21 50
83 23 75
85 25 75
87 27 100
89 29 100
91 31 125
93 33 125
95 35 150
97 37 150
99 39 175
101 41 175
103 43 200
105 45 200
107 47 225
109 49 225];
lamt = [47
43
21
43
17
17
47
45
43
19
33
29];
[ism_lamt,idx_lamt] = ismember(lamt,radius_gl(:,2));
r2 = radius_gl(idx_lamt(ism_lamt),3)
Or, if you know all elements of lamt are in radius_gl(:,2), you can do away with ism_lamt:
[~,idx_lamt] = ismember(lamt,radius_gl(:,2));
r2 = radius_gl(idx_lamt,3)
추가 답변 (1개)
Sulaymon Eshkabilov
2024년 1월 7일
Understood your question correctly, this is what you are trying to achieve:
radius_gl = readmatrix('D_GAMT.txt'); % Copied your sample data
lamt = readmatrix('D_LAMT.txt'); % Copied your sample data
gamt = lamt+randi(2, numel(lamt), 1); % Sample data created
idx_gamt = find(ismember(radius_gl(:, 1), gamt, "rows"));
idx_lamt = find(ismember(radius_gl(:, 2), lamt, "rows"));
r1 = radius_gl(idx_gamt, 3)
r2 = radius_gl(idx_lamt, 3)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!