Borrar filtros
Borrar filtros

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

3 visualizaciones (últimos 30 días)
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

Respuesta aceptada

Walter Roberson
Walter Roberson el 18 de Sept. de 2013
z = arrayfun( @distance, x, c );

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by