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