Fucntion input Varargin, value or name.
1 view (last 30 days)
Show older comments
Im trying to load data from an IMU, but I struggle interpeting what i need to use as input for varagi parmater.
Can anyone explane what i have to type inn her,
Imu = loadImu( FileName, varargi(What do i need to write here?))
Example of the code i want to load,
function [ Imu ] = loadImu( FileName, varargi)
%%Arguments
MASTER = 'RA';
option = 'sync';
FsOut = 512;
nVarargs = length(varargin);
for iArg = 1:2:nVarargs
if strcmp(varargin{iArg}, 'Master'), MASTER = varargin{iArg+1};
elseif strcmp(varargin{iArg}, 'option'), option = varargin{iArg+1};
elseif strcmp(varargin{iArg}, 'Fs')
FsOut = varargin{iArg+1};
resampleData = 1;
else error('Invalid argument.');
end
end
0 Comments
Accepted Answer
Guillaume
on 25 Jan 2018
Assuming that the first line of the function is
function [ Imu ] = loadImu( FileName, varargin)
and not
function [ Imu ] = loadImu( FileName, varargi)
as you have written, then you can call it with
Imu = loadImu(somefilename);
%or
Imu = loadImu(somefilename, 'Master', somevalue)
%or
Imu = loadImu(somefilename, 'option', somevalue)
%or
Imu = loadImu(somefilename, 'Fs', somevalue)
or any combination of the extra arguments in any order
0 Comments
More Answers (1)
Steven Lord
on 25 Jan 2018
I suspect that is a typo in the file, and the second element in the input argument list should be "varargin" not "varargi".
But I don't know what this function expects as its second, third, etc. input arguments. You'd need to ask the person that gave you that code, and ask them to add some help text indicating what it expects and/or can accept. From the if / elseif structure in the code it accepts parameter names 'Master', 'option', or 'fs' but I don't know what the values of those parameters should be.
0 Comments
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!