create a new matrices by using existing matrices

조회 수: 1 (최근 30일)
tevzia
tevzia 2013년 11월 13일
답변: Vivek Selvam 2013년 11월 13일
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에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by