create a new matrices by using existing matrices

1 view (last 30 days)
Hi,
I try to create a new matrices by using specific condition from existing matrices(its a data file) for example I have
a= [1,2,10;
1, 3, 20;
1, 4, 5;
1, 5, 7;
2, 3, 3;
2, 4, 1;
2, 5, 3;
3, 4, 6;
3, 5, 4;
4, 5, 8];
(first and second column are points and third one is the distance of each other) I want point number 2, 3 and 4 in the new matrices (those numbers (x) are come from another matrices(y) which are index of zeros)
x=find(y==0);
result supposed to be (just those numbers, not all of them)
b=[2,3,3;
2,4,1;
3,4,6];
not like this
b=[2,3,3;
2,4,1;
2,5,3;
3,4,6
3,5,4];
I am sorry if i cant explain well or it seems like do for me. I appreciate for some tip

Accepted Answer

Vivek Selvam
Vivek Selvam on 13 Nov 2013
Hope this helps.
x = a(:,1)
y = a(:,2)
want = [2 3 4]
choose = ismember(x,want) & ismember(y,want)
a(choose,:,:)

More Answers (0)

Community Treasure Hunt

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

Start Hunting!