how to find subsets of different matrices

2 Ansichten (letzte 30 Tage)
Sravan Kumar
Sravan Kumar am 25 Mär. 2016
Beantwortet: Stephen23 am 25 Mär. 2016
i have matrices as c1=[1 5 6] c2=[3 2 0] c3=[4 7 0] and another matrix as b=[3 5 6]. now the elements in b matrix appears more in which of c1 c2 c3. assign this b matrix to that. for this problem the b=[3 5 6] goes to c1. so the required output will be [1 5 6], [3 5 6]

Akzeptierte Antwort

Stephen23
Stephen23 am 25 Mär. 2016
Numbered variables are a bad idea. Using numbered variables will make writing code harder. So the first thing to do is put all of those C1s into one variable M:
>> M = [c1;c2;c3]
M =
1 5 6
3 2 0
4 7 0
Then your task is trivial using bsxfun, sum, and max:
>> [~,idx] = max(sum(bsxfun(@eq,M,b),2));
>> [M(idx,:);b]
ans =
1 5 6
3 5 6

Weitere Antworten (1)

Joseph Cheng
Joseph Cheng am 25 Mär. 2016
use the function ismember(). with that you can see which matrices have the most in common.
  1 Kommentar
Sravan Kumar
Sravan Kumar am 25 Mär. 2016
can u please give some more imformation. how to use ismember() for the given problem

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Operators and Elementary Operations finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by