Fucntion input Varargin, value or name.
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Guillaume
2018-1-25
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 个评论
更多回答(1 个)
Steven Lord
2018-1-25
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!