is it possible to use a function in a vectorization
Mostrar comentarios más antiguos
is it at all possible to use function like sum, mean, or sqrt within a vectorization? for example
output(:,3) = sum([ output(:,1) output(:,2) ])
I know that in this case it is simple to just add the two columns without using sum, but I want to use several functions in a more complicated computation, however I can't even get this to work.
1 comentario
Andrei Bobrov
el 31 de Oct. de 2011
output(:,3) = sum(output(:,1:2),2)
Respuesta aceptada
Más respuestas (5)
Jan
el 31 de Oct. de 2011
0 votos
As you can see by running your example, it is possible. Even more, it is the idea behind vectorization to use function inside the vectorization.
If you fail with a complicated computation, post it here together with the occurring error messages.
Note: Your example looks strange. If output is a nx3 matrix, the sum will reply a 1x2 vector, But this is unlikely to match into output(:, 3). Posting real examples is usually better.
2 comentarios
jelle
el 31 de Oct. de 2011
Jan
el 31 de Oct. de 2011
Is constantVector a [1 x N] row vector?
It is hard to guess such details, and if my guessing is wrong, I'm not helping but confusing you. Please post an example of the code, which inlcude all relevant parts (but not more) and which runs except for the line causing troubles.
jelle
el 31 de Oct. de 2011
jelle
el 1 de Nov. de 2011
jelle
el 1 de Nov. de 2011
Categorías
Más información sobre Logical en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!