필터 지우기
필터 지우기

Calling same function repeatedly for different set of input parameters,with out using for loop.

조회 수: 3 (최근 30일)
Hi... x= 1 2
2 3
4 5
x is a 3x2 matrix
z1 = distance(x1,c1);
z2 = distance(x2,c2);
z3 = distance(x3,c3);
x1 - first row of 'x' ;
x2-second row of 'x';
x3-third row of 'x'.
similarly like 'x','c' is also 3x2 matrix. where c1-first row of 'c';similarly 'c2' and 'c3'.
'distance' is a function which takes two inputs,and compute the the distance between the two inputs and return it.
i know that above can be implemented by using for-loop but is there any better way,instead of looping,so that i get 'z' as a 3x1 matrix.
z(1,1)=z1;
z(2,1)=z2;
z(3,1)=z3;
Regards,
Chandradhar Savanth

채택된 답변

Walter Roberson
Walter Roberson 2013년 9월 18일
z = arrayfun( @distance, x, c );

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by