without using loops

조회 수: 5 (최근 30일)
osman
osman 2011년 10월 4일
i have a large scale of data. i need to do the following job without using loops
z=[1,2,3,4;5,18,7,8;12,16,35,-8];
yuk=max(z(:,1:end));
i want to search "yuk" vectors elements in the "z" matrice. but i want to search yuk(1) only for first column of the z matrice , the yuk(2) to the second column of the matrice and so on. how can i do that
thanks
  댓글 수: 2
osman
osman 2011년 10월 4일
x=[2,3,4,5;1,3,2,5;8,7,6,5];
y=[-1,2,3,6;8,6,7,5;10,11,12,18];
z=[1,2,3,4;5,18,7,8;12,16,35,-8];
[yuk,idx]=max(z) %as andrei says (http://www.mathworks.com/matlabcentral/answers/17409-without-using-loops)
here z is a function of x and y and the question is to find which corresponds to the max z in each column in the matrices x and y
in short i need to find elements of matrices in each column using idx without using loops For example in the 1. colum max z is 12 and find x is 8 y is 10
Andrei Bobrov
Andrei Bobrov 2011년 10월 4일
[m n] = size(x)
ind = sub2ind([m n],idx,1:n)
xout = x(ind)
yout = y(ind)

댓글을 달려면 로그인하십시오.

채택된 답변

Andrei Bobrov
Andrei Bobrov 2011년 10월 4일
[yuk,idx] = max(z)
  댓글 수: 1
Daniel Shub
Daniel Shub 2011년 10월 4일
Wow, nice job piecing that together from the question.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

osman
osman 2011년 10월 4일
thanks

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by