0

Possible Duplicate:
How do I get the second return value from a function without using temporary variables?

As part of an attempt to do K-fold cross-validation, I'm trying to write an anonymous function that returns the 4th argument of another function.

Specifically, the function SVM returns five argument, and I want to create an anonymous function that picks out the fourth.

I thought this would work

Func1 = @(x) sum( SVM(x) .* [0, 0, 0, 1, 0] )

but sadly, it does not - it just returns the first argument.

Any ideas?

Thanks!

Community
  • 1
  • 1
Daniel G
  • 143
  • 8
  • 6
    Related/Possible duplicates: [How do I get the second return value from a function without using temporary variables?](http://stackoverflow.com/q/3710466/52738), [How to elegantly ignore some return values of a MATLAB function?](http://stackoverflow.com/q/747296/52738) – gnovice Nov 01 '12 at 16:14
  • I'd say it's a duplicate of the former. – Jonas Nov 01 '12 at 16:22
  • Yeah, it is indeed. What I was asking, though, was whether there's a way to do this without adding (yet another) Matlab function file that I then have to send to any collaborator I want to share this with... I didn't make it clear in the original question, sorry... – Daniel G Nov 01 '12 at 16:33
  • If you only need to do this in one location, you can use the approach in the first link above, but make the helper function local to the file. If you need to do it in more than one file, you should just bite the bullet and make the new function file. One file per reusable function is one of those annoying things about MATLAB that we all have to suffer through. – Dan Becker Nov 01 '12 at 17:51
  • Thanks, Dan, appreciate the answer - that's what I thought. I didn't want to do it because it was in an m file, but I guess I'll just have to bite the bullet and convert it to a function file with that private function you suggest. This ridiculous restriction in re: how and where functions can be defined is definitely by number 1 pet peve with Matlab! – Daniel G Nov 01 '12 at 18:07
  • I don't know the function SVM...is that your own? In any event, you do know, I presume, that you can use tildes to ignore unwanted outputs? For instance, >> a = rand(2,3,5); >> [~,~,thirdDim] = size(a); thirdDim = 5 – Brett Shoelson Nov 01 '12 at 19:02

0 Answers0