compare between element of matrix in different size

1 view (last 30 days)
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

Answers (1)

Shubham Gupta
Shubham Gupta on 25 Oct 2019
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 !

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!