How to elegantly ignore some return values of a MATLAB function?

Answer

This is somewhat of a hack but it works:

First a quick example function:

Func3=@() deal(1,2,3);[a,b,c]=Func3();% yields a=1, b=2, c=3

Now the key here is that if you use an variable twice in the left hand side of a multiple-expression assignment, an earlier assignment is clobbered by the later assignment:

[b,b,c]=Func3();% yields b=2, c=3[c,c,c]=Func3();% yields c=3

(edit: just to check, I also verified that this technique works with [mu,mu,mu]=polyfit(x,y,n) if all you care about from polyfit is the 3rd argument)

All matlab Questions

Ask your interview questions on matlab

Write Your comment or Questions if you want the answers on matlab from matlab Experts
Name* :
Email Id* :
Mob no* :
Question
Or
Comment* :
 





Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---