Multiple Output Anonymous function: Using one output value for another output.
Afficher commentaires plus anciens
I have an anonymous function that gives two output and what it does is takes an index 'x' to a vector, 'rowValues', and then gives two outputs where the first one is all the non-zero elements in a 9 element window centered at 'x' and the second output is a vector of length of first output and where all elements are just the element present at the index 'x'.
func=@(x) deal(nonzeros(rowValues(x-4:x+4)),...
repmat(rowValues(x),1,length(nonzeros(rowValues(x-4:x+4))));
As you can see, I am using the length of the first output for creating the second output but I don't think this is an efficient way of doing this because "nonzeros(rowValues(x-4:x+4))" is being evaluated twice. Is there any way that I can use some kind of a handle for the first output to use for the second one? Another question in extension is that, in which order does matlab calculate the output values, is it from left to right or right to left? Any help would be greatly appreciated!!
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Logical dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!