Multiple Output Anonymous function: Using one output value for another output.
显示 更早的评论
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!!
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!