Clear Filters
Clear Filters

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

3 views (last 30 days)
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

Accepted Answer

Walter Roberson
Walter Roberson on 18 Sep 2013
z = arrayfun( @distance, x, c );

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!