compare between element of matrix in different size
조회 수: 1 (최근 30일)
이전 댓글 표시
hi, i need some help here. I want to compare element between two matrices new_mat[40x11] and kmatrix[1x4].
If the 11th columns of each row in new_mat == to any element in kmatrix, it will create an another matrix call cluster_k containing element column i until 10 from new_mat
for example new_mat
[11 12 13 14 15 16 17 18 19 13 1]
[11 12 13 14 15 16 17 18 19 14 2]
[11 12 13 14 15 16 17 18 19 15 3]
kmatrix [1 2 3 4]
so will have
cluster_1 [[11 12 13 14 15 16 17 18 19 13]
cluster_2 [11 12 13 14 15 16 17 18 19 14]
cluster_3[11 12 13 14 15 16 17 18 19 15 3]
Do appreciate some help.
Below is my current code:
new_mat = [C index]
i=1
kmatrix = [1:k]
for n = i:40
if (new_mat(i,11))== kmatrix[1:k] %stuck here
cluster_k = new_mat(i,10) % and here too
end
i=i+1
end
댓글 수: 0
답변 (1개)
Shubham Gupta
2019년 10월 25일
To check if there is any common element between 2 vectors, you may consider using 'intersect()'. So, your if condition becomes:
if isempty(intersect(new_mat(i,11)),kmatrix)
%% create cluster_k
end
Let me know if you have doubts !
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!