From: mat001 on 19 May 2010 05:23 I defined % pick.m function [A,B,C] = pick(x,y,z) A = x+y; B = y; C = x; % end of function In another .m file if i need only A or B then how to call. I do not want to use gloabl.
From: David Young on 19 May 2010 05:52 The simplest thing is just to call it like this [A,B,C] = pick(x,y,z) and then don't use A or B or C if you don't need them. Presumably you want to do something more than this, but I'm not exactly sure what. In recent versions of Matlab you can write, for example [~,B,~] = pick(x,y,z) if you only want B. In all versions you can write A = pick(x,y,z) if you only want A. If you want to select the output using a number to choose one of the three, you might do this: results = cell(1,3); [results{:}] = pick(x,y,z); result = results{k} where the value of k determines whether you get A, B or C. If you are happy to change the function pick, then you could pass an extra argument to it, to specify which result it should return, as in function a = pick(x,y,z, k) switch k case 1 a = x+y; % or whatever case 2 a = y+z; % or whatever case 3 a = z; otherwise error('k out of range'); end end
|
Pages: 1 Prev: problem with getting the rights graphs Next: hessian help! |