Fucntion input Varargin, value or name.

1 visualización (últimos 30 días)
Espen Bekkelien
Espen Bekkelien el 25 de En. de 2018
Respondida: Steven Lord el 25 de En. de 2018
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

Respuesta aceptada

Guillaume
Guillaume el 25 de En. de 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

Más respuestas (1)

Steven Lord
Steven Lord el 25 de En. de 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.

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by