Fucntion input Varargin, value or name.

1 visualizzazione (ultimi 30 giorni)
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

Risposta accettata

Guillaume
Guillaume il 25 Gen 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

Più risposte (1)

Steven Lord
Steven Lord il 25 Gen 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.

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by