create a new matrices by using existing matrices

1 次查看(过去 30 天)
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

采纳的回答

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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by