Prev: matlab functions
Next: working with structures
From: wm m on 26 Apr 2010 22:14 Hi, I am wondering if it is legal to return a structure from a matlab function. Also, is it allowed to take as input to a function a matlab structure. I would appreciate some examples if it is possible to do so. Thanks. Majid
From: Image Analyst on 26 Apr 2010 22:51 Example: In file test1.m: function test1 clc; inputStruct.v1 = 42; inputStruct.v2 = 69 outputStruct = MakeStruct(inputStruct) return; function outputStr = MakeStruct(inputStr) outputStr.Value1 = 10 * inputStr.v1; outputStr.Value2 = 10 * inputStr.v2; return;
From: us on 27 Apr 2010 00:27 "wm m" <wm.do.not.use(a)yahoo.com> wrote in message <hr5h9d$2ol$1(a)fred.mathworks.com>... > Hi, > > I am wondering if it is legal to return a structure from a matlab function. Also, is it allowed to take as input to a function a matlab structure. I would appreciate some examples if it is possible to do so. > > Thanks. > > Majid suffice it to say: yes, of course... no examples need to clutter CSSM - just create some code by yourself... us
From: Steven Lord on 27 Apr 2010 09:55 "wm m" <wm.do.not.use(a)yahoo.com> wrote in message news:hr5h9d$2ol$1(a)fred.mathworks.com... > Hi, > > I am wondering if it is legal to return a structure from a matlab > function. Sure, a struct array is a regular MATLAB variable and so there's no reason it wouldn't. Is there something you read/heard that would imply otherwise? If so, I'd appreciate a link to whatever it is; if it's part of our documentation, perhaps we need to revise that part to make it clearer. > Also, is it allowed to take as input to a function a matlab structure. See above. > I would appreciate some examples if it is possible to do so. There are many functions that return struct arrays -- probably the most commonly used one is DIR. D = dir('*.m') For functions that accept a struct ... most of the ones that come to mind have many additional inputs, but here's one that displays the contents of a struct. function displayStructure(S) if ~isstruct(S) error('displayStructure:notAStruct', 'Input argument must be a struct array.'); end fn = fieldnames(S); for k = 1:numel(fn) fprintf('S has a field %s.\n', fn{k}); end -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
|
Pages: 1 Prev: matlab functions Next: working with structures |